Difference between <?php ?> and <? ?>

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hdogg
    New Member
    • Mar 2007
    • 7

    Difference between <?php ?> and <? ?>

    What is the difference? Any.. besides that one has the word "php" in it?
  • mwasif
    Recognized Expert Contributor
    • Jul 2006
    • 802

    #2
    <? ?> is called short tag.
    If short_open_tag is disbaled in php.ini then only <?php and <script> tags are recognized.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, hdogg.

      Short tags are supported because ASP Users are used to '<%' and '%>'. You can also use '<?=' as a shortcut for '<?php echo '.

      As a general rule, I like to avoid short tags because they interfere with XML declarations ('<?xml').

      Using short tags also tends to encourage combining HTML and PHP together, which I don't generally agree with; I feel very strongly that it is important to keep your display code separate from your op code (http://en.wikipedia.org/wiki/Model-view-controller).

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        It is also generally not good practice to use short tags as they are turned off by default (PHP5) which will create problems if you move your code to another machine or if your code is used by someone who does not know the difference.

        And as pbmods said, they encurage inlining PHP code with HTML markup which generally makes code ugly and hard to read.

        Comment

        Working...