开发者

Setting for <? and <?php

I am running 5.2.14. Starting php code code using <? does not work. I must use <?php

For example:

Does not work:

<? phpinfo(); ?>

Does work:

<?php phpinfo(); ?>

Where can I change this setting so 开发者_开发问答<? will work?


edit yout php.ini file, and set short_open_tag = On

you can view the php.ini's path by runing phpinfo(); function...

but, you can just write your scripts starting with <?php

Mike ;]


It is best not to use the short tag <? in place of the normal <?php. If you ever need to host on a server that doesn't support editing the PHP configuration, it is a pain to find and replace the short tags with the standard ones.

From http://php.net/manual/en/ini.core.php:

Tells PHP whether the short form (<? ?>) of PHP's open tag should be allowed. If you want to use PHP in combination with XML, you can disable this option in order to use inline. Otherwise, you can print it with PHP, for example: <?php echo '<?xml version="1.0"?>'; ?>. Also, if disabled, you must use the long form of the PHP open tag (<?php ?>).


Yeah as mishunika says change your php.ini file though be warned, if moving to another server later on it might not work. If you don't have access to the php.ini file on the other server you'll have to change them over to

<?php

Any reason you don't want to use the long tag?


I agree with everyone in regards to using short tags. You should for compatibility reasons stay away from short tags. However, there are situations which may call for it. For example, if you are trying to use a PHP script that someone else wrote that uses short tags, then you can either modify the code or enable short_open_tag.

If you do not have writable access to the php.ini file (shared hosting) you may be able to set the flag using the PHP function "ini_set". You can read up on the function here:

PHP ini_set

There are some flags and variables you cannot set with ini_set. I haven't personally tried to set the short_open_tag. Give it a shot.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜