www.webdeveloper.com
Results 1 to 7 of 7

Thread: why some php code can use <? ....?> instead of <?php...?>

  1. #1
    Join Date
    May 2008
    Posts
    27

    why some php code can use <? ....?> instead of <?php...?>

    this is really a beginner's question....

    I found that my machine as a local server can only run the code of <?php..?>

    but another remote server can run the code of <?....?>

    like

    PHP Code:
            <?
                
    echo "Greetings from PHP.";
            
    ?>
    does not work on my machine but work on another server. why?

    I am using apache on windows xp.

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    short_open_tag is set to "1" in php.ini (default) which does not allow the <? ?>
    It is considered best practice to use <?php ?>
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    You could also use

    <script type="application/php"> </script>

    if you want to use an even longer version of the tags.
    Stephen

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Quote Originally Posted by felgall
    You could also use

    <script type="application/php"> </script>

    if you want to use an even longer version of the tags.
    According to the manual (with my emphasis added):
    There are four different pairs of opening and closing tags which can be used in php. Two of those, <?php ?> and <script language="php"> </script>, are always available. The other two are short tags and ASP style tags, and can be turned on and off from the php.ini configuration file. As such, while some people find short tags and ASP style tags convenient, they are less portable, and generally not recommended.
    Also, I believe the plan is to not even have the short_open_tag option available at all in PHP 6, so in addition to the other good reasons to avoid "<?" and "<?=", forward compatibility is another reason.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    May 2008
    Posts
    27
    Thank you guys!

  6. #6
    Join Date
    Mar 2005
    Location
    Sydney, Australia
    Posts
    7,974
    Oops. I misremembered how to code the PHP script tag. For some reason I thought it was similar to an HTML script tag and of course HTML script tags don't have a language attribute. I wonder why they didn't make the PHP script tag similar to the HTML one?
    Stephen

  7. #7
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,176
    Quote Originally Posted by felgall
    Oops. I misremembered how to code the PHP script tag. For some reason I thought it was similar to an HTML script tag and of course HTML script tags don't have a language attribute. I wonder why they didn't make the PHP script tag similar to the HTML one?
    I figured you were diligently trying to write valid, strict [X]HTML.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles