开发者

php have some rules with the open tag <? ?>? [duplicate]

开发者 https://www.devze.com 2023-03-13 17:40 出处:网络
This question already has answers here: How to enable PHP short tags? (21 answers) Closed 1 year ago. I have an application that has some PHP code, the PHP open/close tag I\'m using is:
This question already has answers here: How to enable PHP short tags? (21 answers) Closed 1 year ago.

I have an application that has some PHP code, the PHP open/close tag I'm using is:

<? 
        $anything;
        echo problem;

?>

The application is 开发者_运维技巧not running.

Are there some rules for this type of open/close ( maybe a php.ini config.) that might cause the application not to run ?

P.S. Would the better way be to change all <? to <?php ?


run a phpinfo(), look for the path which php.ini is used. Then open the file and find short_open_tag

Set it to on or off.

But in general.. use <?php ?> this is better.


Use <?php ?>. <? ?> are referred to as short-tags, and not every server is setup to support them.


The <? version of the open tag is called a "short tag." While the php community prefers the use of the full <?php version of this tag, it is still acceptable to use short tags. Ideally, we would all use <?php all the time, but we often deal with legacy code, and changing all occurrences of <? to <?php can be tedious and time consuming. If you find yourself in a situation where you need to allow the php interpreter to recognize the short tag, you may enable it in the php.ini file using the "short_open_tag=1" directive.

For new code you are developing, I would recommend using the long version of the tag <?php, as you know that will be compatible regardless of the ini setting used in the servers php.ini config. For more information on this, see: Are Php Short Tags Acceptable To Use here on StackOverflow.

To figure out why your application is not running, check the webserver error logs, as well as the php error logs, and consider turning up php's error reporting level. This can also be done in the php.ini file using the error_reporting directive. This will allow you to determine what is causing the application to not run, and then you will be more informed for further questions.


You should use <?php ?> to ensure correct parsing.


There are specific times where it is suited or possible to use the short tags like this for PHP

<?=$sign['last_connected']?>

notice the <?= instead of <?php echo

0

精彩评论

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