简体   繁体   English

省略单词php以打开标签

[英]Omitting the word php for opening tags

I mean: 我的意思是:

<?php echo "hello"; ?>

against: 反对:

<? echo "hello"; ?>

(without the php ). (没有php )。

It works right, but is there any consequence/bad programming practice?? 它工作正常,但是有什么后果/不良的编程习惯吗? There is no problem?? 没有问题?? Is everything OK? 一切都顺利吗? What can happen? 会发生什么?

Paraphrased from the PHP manual : 摘自PHP手册

  • <?php should always work. <?php应该总是可以工作。
  • <? only works if short_open_tag = On in php.ini . 仅在php.ini short_open_tag = On起作用。
  • <?= (equivalent to <?php echo ) should always work in PHP 5.4 and newer. <?= (等同于<?php echo )应始终在PHP 5.4和更高版本中运行。 In PHP 5.3 and older, it does require short_open_tag = On . 在PHP 5.3和更早的版本中,它确实需要short_open_tag = On

So if you are writing a PHP app for others to use, it is best to stick with <?php (and <?php echo if you decide to support PHP 5.3 or older). 因此,如果要编写供他人使用的PHP应用程序,则最好坚持使用<?php (如果决定支持PHP 5.3或更早版本,则应使用<?php echo )。 If you can control the server's configuration, you can use <? 如果可以控制服务器的配置,则可以使用<? if you want to. 如果你想。

Use, for example, <?php echo '<?xml version="1.0"?>'; ?> 例如使用<?php echo '<?xml version="1.0"?>'; ?> <?php echo '<?xml version="1.0"?>'; ?> if you have to output an XML prolog or processing instruction manually (as opposed to using PHP's XML functions to do it). <?php echo '<?xml version="1.0"?>'; ?>如果您必须手动输出XML序言或处理指令(与使用PHP的XML函数相反)。

It works right, but is there any consequence/bad programming practice?? 它工作正常,但是有什么后果/不良的编程习惯吗? there is no problem?? 没有问题?? is everything ok? 一切都顺利吗? what can it happen? 会发生什么?

Well, not every hosting allows short-open-tag . 好吧,并非每个托管都允许short-open-tag So <?php is a better option if your script target large audience. 因此,如果您的脚本面向大量受众,则<?php是一个更好的选择。 Or you often change your hosting. 或者您经常更改主机。

if short_open_tag is open, the short form (<? ?>) will work. 如果short_open_tag是打开的,则short form (<? ?>)将起作用。

anyway the long form is a standard. 无论如何, long form是一个标准。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM