<? ?> 标签在 php 5.3.1 中不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2476072/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
<? ?> tags not working in php 5.3.1
提问by dhvani
I just installed php 5.3.1 in my linux server and now my old work which i used to write with tags is not working at all..
我刚刚在我的 linux 服务器中安装了 php 5.3.1,现在我以前用标签编写的旧工作根本无法工作..
Please help me out.. How can i resolve this??
请帮帮我.. 我该如何解决这个问题?
回答by Felix Kling
To enable short tags, enable the short_open_tagini directive in one of the following ways (most probably not all of them will work for you):
要启用短标签,请short_open_tag通过以下方式之一启用ini 指令(很可能并非所有这些都适合您):
- set the directive
short_open_tag = Onin your php.ini (the recommended way); - call
ini_set("short_open_tag", 1);in your code; add the following line to your .htaccess file:
php_value short_open_tag 1
short_open_tag = On在 php.ini 中设置指令(推荐方式);- 调用
ini_set("short_open_tag", 1);您的代码; 将以下行添加到您的 .htaccess 文件中:
php_value short_open_tag 1
More explanation:
更多解释:
It's not recommend you use short tags(<? ?>). You should use the full length tags (<?php ?>). The short syntax is deprecated, and if you want to make your application portable, it's possiblethat short open tags are not allowed on another server and hence your application will break.
不建议您使用短标签( <? ?>)。您应该使用全长标签 ( <?php ?>)。短语法已被弃用,如果您想让您的应用程序具有可移植性,则另一台服务器上可能不允许使用短的开放标签,因此您的应用程序将中断。
On the other hand, the echo shorthand <?= $var ?>is enabled by default since PHP 5.4regardless of php.ini settingsand will not be deprecated. You can use it instead of <?php echo $var; ?>
在另一方面,回声速记<?= $var ?>是在默认情况下,因为PHP 5.4启用不管php.ini设置并不会过时。你可以用它代替<?php echo $var; ?>
And for the default behaviour:
对于默认行为:
------------------------------------------------
php.ini values : short_open_tag
------------------------------------------------
PHP 4, 5_0
* Default behaviour : on
* php.ini-dist : on
* php.ini-recommended : on
PHP 5_1, 5_2:
* Default behaviour : on
* php.ini-dist : on
* php.ini-recommended : off
PHP 5_3:
* Default behaviour : on
* php.ini-development : off
* php.ini-production : off
And the reason of discouraging short open tags:
以及不鼓励短开放标签的原因:
This directive determines whether or not PHP will recognize code between
<?and?>tags as PHP source which should be processed as such. It's been
recommended for several years that you not use the short tag "short cut" and
instead to use the full<?phpand?>tag combination. With the wide spread use of XML and use of these tags by other languages, the server can become easily
confused and end up parsing the wrong code in the wrong context. But because
this short cut has been a feature for such a long time, it's currently still
supported for backwards compatibility, but we recommend you don't use them.
该指令确定 PHP 是否将
<?和?>标记之间的代码识别为 PHP 源代码,应按原样处理。
多年来一直建议您不要使用短标签“快捷方式”,
而是使用完整<?php和?>标签组合。随着 XML 的广泛使用以及其他语言对这些标签的使用,服务器很容易
混淆并最终在错误的上下文中解析错误的代码。但是因为
这个捷径已经成为一个功能很长时间了,它目前仍然
支持向后兼容,但我们建议你不要使用它们。
Note also this declined RFC about short open tags for templates: http://wiki.php.net/rfc/shortags
还要注意这拒绝了关于模板的短开放标签的 RFC:http: //wiki.php.net/rfc/shortags
回答by Yo-L
Looks like you got short_open_tags set to "Off" in your php.ini file. Try setting it to "On" and restart apache.
看起来您在 php.ini 文件中将 short_open_tags 设置为“关闭”。尝试将其设置为“开”并重新启动 apache。
回答by Mark Embling
You most likely need to turn on short tags in your PHP configuration file. Without knowing your configuration, I couldn't say where you'd find it, but you're looking for php.ini (most likely somewhere like /etc/php.ini).
您很可能需要在 PHP 配置文件中打开短标签。在不知道您的配置的情况下,我无法确定您会在哪里找到它,但您正在寻找 php.ini(很可能在某个地方/etc/php.ini)。
In there, the setting you are after is short_open_tags. See herefor all core configuration settings for PHP. However as others have mentioned, using short tags might not be the best strategy. Hereis a good discussion of the reasons (for and against).
在那里,您所追求的设置是short_open_tags。有关PHP 的所有核心配置设置,请参见此处。然而正如其他人提到的,使用短标签可能不是最好的策略。这是对原因(支持和反对)的很好的讨论。
回答by Osin Toumani
If you use wamp or xamp, it's really easy to activate them. Just click on icon->php server->setting->allow short tag open
如果您使用 wamp 或 xamp,激活它们真的很容易。只需点击icon->php server->setting->allow short tag open
It's better to not use this functionality. For example xml use the same way to open header in docs.
最好不要使用此功能。例如 xml 使用相同的方式在文档中打开标题。
回答by Sinan
maybe your new configuration doesnt alllow short tags. Just use <?php ?>. It is better practise anyway.
也许您的新配置不允许短标签。只需使用<?php ?>. 无论如何,这是更好的练习。
If you still want to use them you can short_open_tagdirective. Also bear in mind that won't work if you have short tags disabled.
如果你仍然想使用它们,你可以short_open_tag指令。还要记住,如果您禁用了短标签,这将不起作用。
The main reason for this is so you can use inline Xml tags.
这样做的主要原因是您可以使用内联 Xml 标记。

