Difference between <?php and <?

后端 未结 7 1158
被撕碎了的回忆
被撕碎了的回忆 2020-11-29 07:57

I am new to php and would like to know if there are any differences between these server tags :


and



        
相关标签:
7条回答
  • 2020-11-29 08:28

    Note short_open_tag = Off did not effect the <?= shorthand tag, which is equivalent to <?php echo

    0 讨论(0)
  • 2020-11-29 08:31

    The first is a safe open and close tag variation, the second is the so called short-open tag. The second one is not always available, use the first option if it's possible. You could check the availability of short open tags in php.ini, at the short_open_tag.

    0 讨论(0)
  • 2020-11-29 08:32

    As @erenon explained here: https://stackoverflow.com/a/1808372/1961535

    The difference is that short_open_tag in some cases isnt available. You can check the status by accessing the php.ini file but in case of shared hosting server, the host does not always allow edits to php.ini file.

    You can easily print the phpinfo as explained here: https://www.php.net/manual/en/function.phpinfo.php

    phpinfo();
    

    search for short_open_tag as shown below

    It is always better to use full tag because that will always be supported in every version of PHP weather old file or new.

    0 讨论(0)
  • 2020-11-29 08:34

    There is no difference.

    The ability to use <? ?> is defined in your php.ini file - usually accessed only by the server host.

    You can find more information here

    0 讨论(0)
  • 2020-11-29 08:39

    Also I think shorttags are being removed in one of the upcomming releases.

    Edit: I was wrong.

    Farewell <% They will remove support for the ASP style tags, but the PHP short-code tag will remain - so to those on php general who reckon the short-tag is 'depreceated' - hah! ;)

    http://phpmysqldev.blogspot.com/2007/05/php-6.html

    0 讨论(0)
  • 2020-11-29 08:41

    Nothing AFAIK, however I have had servers (shared) where the settings do not support shorthand tags <? ?>, so I usually stick with the <?php ?> for good measure.

    0 讨论(0)
提交回复
热议问题