SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Thread: <? or <?php

  1. #1
    SitePoint Addict Andrei P.'s Avatar
    Join Date
    Jul 2004
    Location
    New York, New York
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <? or <?php

    I code PHP for a while now, and I always asked myself: what's the difference between using <? and <?php to start the PHP code in an HTML file?

    I thought maybe it depends on the version, just like the numerous ways to start a JavaScript, depending on the version.
    Or maybe <?php is used not to be confused with other server side languages that start with <?...

    Anyway, most of the time I use <?php.

  2. #2
    SitePoint Enthusiast nathanj's Avatar
    Join Date
    Dec 2004
    Location
    Perth, WA, Australia
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I like to use <?php only because some other languages use <? I think.

  3. #3
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <? is known as the open_short_tag. Whether this is allows is goverened by the open_short_tag directive in the php.ini configuration file.

    Given that this can be either true (short tag is allowed) or false (short tag not allowed) I would always use the long form (<?php).

  4. #4
    SitePoint Addict Andrei P.'s Avatar
    Join Date
    Jul 2004
    Location
    New York, New York
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm, so this is it... I smelled something when I saw that everyone on php.net is using <?php.

  5. #5
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually, it's short_open_tag . For portability reasons you should always use <?php . If you only develop for your own system, it doesn't matter what you use.

  6. #6
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As swdev said, it is always best to use the <?php tag to avoid any issues thay may crop up if you ever deploy your scripts into different environments!

    - Mark

  7. #7
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Icheb
    Actually, it's short_open_tag . For portability reasons you should always use <?php . If you only develop for your own system, it doesn't matter what you use.
    Sorry..... posted at the same time!


  8. #8
    SitePoint Addict Andrei P.'s Avatar
    Join Date
    Jul 2004
    Location
    New York, New York
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, thanks for your answers. I will always use <?php from now on... as a freelance programmer you never know on what server the code ends up.

  9. #9
    SitePoint Wizard Mike Borozdin's Avatar
    Join Date
    Oct 2002
    Location
    Edinburgh, UK
    Posts
    1,743
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <?php was invented to avoid confusing with XML syntax - <?xml version="1.0" encoding="UTF-8" ?>

  10. #10
    SitePoint Zealot Koobi's Avatar
    Join Date
    Nov 2003
    Location
    Sri Lanka
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've also read somewhere that using <? can confuse PHP with XML unless a certain directive is set in php.ini...what that directive is, is what I can't confirm :/

  11. #11
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Icheb - thanks for the correction. Brain must be working in reverse

    Koobi - the ini file directive is short_open_tag which is set to true to enable short tags or false to disable them

  12. #12
    SitePoint Enthusiast nathanj's Avatar
    Join Date
    Dec 2004
    Location
    Perth, WA, Australia
    Posts
    67
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  13. #13
    Non-Member Icheb's Avatar
    Join Date
    Mar 2003
    Location
    Germany
    Posts
    1,474
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Which is just yet another way of saying what has already been said.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •