PHP 短开放标签与长开放标签

发布于 2024-12-14 01:01:52 字数 282 浏览 7 评论 0原文

可能的重复:
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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

赏烟花じ飞满天 2024-12-21 01:01:52

是官方标准。我从未遇到过浏览器感到困惑的问题,但仅使用 也可以声明 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.

假面具 2024-12-21 01:01:52

- 总是,绝对。

有几个原因;最大的问题是“消除 PHP 与 SGML(例如 XML)的歧义”。

<?php - always, definitely.

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

水晶透心 2024-12-21 01:01:52

从 PHP 5.4 开始,无论 short_open_tags ini 参数如何,都将可用,因此,如果您具有前瞻性,则可以不用使用 在 HTML 中,代替 ,但是对于非 echos 始终使用 作为 < ;? 仍然取决于在ini上。

也就是说,许多主机最近才采用 5.3,而 5.4 仅处于测试阶段,因此如果这是一个库或可能很快到达其他服务器的东西,我会坚持使用

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.

山田美奈子 2024-12-21 01:01:52

我可能会推荐 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文