&lt ;? ?>标记在php 5.3.1中不起作用 [英] <? ?> tags not working in php 5.3.1

查看:80
本文介绍了&lt ;? ?>标记在php 5.3.1中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在Linux服务器上安装了php 5.3.1,现在我以前用标签编写的旧作品根本不起作用.

请帮帮我. 我该如何解决呢?

解决方案

要启用短标签,请通过以下方式之一启用short_open_tag ini指令(很可能并非所有这些都对您有用):

  • 在php.ini中设置指令short_open_tag = On(推荐方式);
  • 在您的代码中调用ini_set("short_open_tag", 1);
  • 将以下行添加到您的.htaccess文件中:

    php_value short_open_tag 1


更多说明:

不建议您使用短标签(<? ?>).您应该使用全长标签(<?php ?>).短语法已被弃用,如果要使应用程序具有可移植性,则可能不允许在另一台服务器上使用短开放标记,因此您的应用程序将损坏.

另一方面,回显速记<?= $var ?> 而是使用完整的<?php?>标签组合.随着广泛的使用 XML以及其他语言对这些标记的使用,则服务器可以轻松变得
困惑,最终在错误的上下文中解析错误的代码.但是因为
这种快捷方式已经有很长一段时间了,目前仍然是
支持向后兼容,但我们建议您不要使用它们.

还请注意,有关模板的短打开标记的RFC有所下降: http://wiki.php.net/rfc/shortags

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..

Please help me out.. How can i resolve this??

解决方案

To enable short tags, enable the short_open_tag ini directive in one of the following ways (most probably not all of them will work for you):

  • set the directive short_open_tag = On in 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


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 possible that short open tags are not allowed on another server and hence your application will break.

On the other hand, the echo shorthand <?= $var ?> is enabled by default since PHP 5.4 regardless of php.ini settings and will not be deprecated. You can use it instead of <?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 <?php and ?> 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.

Note also this declined RFC about short open tags for templates: http://wiki.php.net/rfc/shortags

这篇关于&lt ;? ?&gt;标记在php 5.3.1中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆