Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
113 views
in Technique[技术] by (71.8m points)

php shorttags - <? ?> tags not working in php 5.3.1

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

question from:https://stackoverflow.com/questions/2476072/tags-not-working-in-php-5-3-1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...