dslh32311 2011-06-22 19:51
浏览 81
已采纳

<?php?>和<?的php语法不同? ?> [重复]

Possible Duplicates:
What is the difference between the PHP open tags “<?=” and “<?php”/“<?”?
Reference - What does this symbol mean in PHP?

Is there really any difference in writing the syntax like <?php ?> or as <? ?>.

I was under the impression that it really didn't matter as long as the file had an .php extension. But sometimes I seem to run into problems with the syntax.

so whats the lowdown?

  • 写回答

3条回答 默认 最新

  • dstxpei5823 2011-06-22 19:52
    关注

    The latter is called shorttags.

    You can disable those tags in php's configuration, apart from that there is not really a difference.

    Because you can disable them, you should not use them, as they can cause lots of unexpected problems when you happen to run your scripts on servers where you can't enable them. Another reason, as noted by Sjoerd in the comment is, that they can cause conflicts when you have an XML header for instance.

    If you enable short tags though, you get a shorthand syntax for the echo function: <?= $string ?>

    It's enabled using the short_open_tag setting in php.ini. You can read about it here.

    Update As of PHP 5.4.0 alpha1:

    <?= is now always available regardless of the short_tags setting (Rasmus)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?