PHP 短开放标签与长开放标签
可能的重复:
PHP 短标签可以使用吗?
哪个更好用,或认为更好的做法:或
。我一直想知道。或者说更多的是程序员的偏好。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
是官方标准。我从未遇到过浏览器感到困惑的问题,但仅使用
也可以声明 XML,但可能不是最好的习惯。
不过我会告诉你这一点 - 其他程序员总是会欣赏这个标准。我肯定会选择
。
<?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.- 总是,绝对。
有几个原因;最大的问题是“消除 PHP 与 SGML(例如 XML)的歧义”。
<?php
- always, definitely.Several reasons; the biggest being "disambiguates PHP from SGML (e.g. XML)".
从 PHP 5.4 开始,无论
short_open_tags
ini 参数如何,都将可用,因此,如果您具有前瞻性,则可以不用使用
在 HTML 中,代替
,但是对于非 echos 始终使用
作为
< ;?
仍然取决于在ini上。也就是说,许多主机最近才采用 5.3,而 5.4 仅处于测试阶段,因此如果这是一个库或可能很快到达其他服务器的东西,我会坚持使用
。
As of PHP 5.4,
<?=
will be available regardless of theshort_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.我可能会推荐 HTML 代码中的
。但是,无论何时我都会推荐
,因为它是标准的,并且通过示例可以减少与 XML 的混淆。
I may recommend
<?= ;?>
in HTML code. But, I will alawys recommend<?php
whenever because it's standard and less confusion with XML by example.