PHP short open tag vs long open tag [duplicate]

狂风中的少年 提交于 2019-12-10 17:35:32

问题


Possible Duplicate:
Are PHP short tags acceptable to use?

Which is better to use, or considered better practice: <?php or <?. I've always wanted to know. Or is it more of a preference for the programmer.


回答1:


<?php is the official standard. I've never encountered a problem where a browser was confused, but just using <? can also declare XML and might not be the best habit to form.

I'll tell you this though - other programmers will always appreciate the standard. I would go with <?php for sure.




回答2:


<?php - always, definitely.

Several reasons; the biggest being "disambiguates PHP from SGML (e.g. XML)".




回答3:


As of PHP 5.4, <?= will be available regardless of the short_open_tags ini parameter, so if you're forward-looking you could get away with using <?= inside HTML, in place of <?php echo, however for non-echos always use <?php as <? still depends on the ini.

That said, many hosts have only recently adopted 5.3, and 5.4 is only in beta so if this is a library or something that might reach other's servers soon, I'd stick with <?php for both.




回答4:


I may recommend <?= ;?> in HTML code. But, I will alawys recommend <?php whenever because it's standard and less confusion with XML by example.



来源:https://stackoverflow.com/questions/8004578/php-short-open-tag-vs-long-open-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!