开发者

Opening php file declaration question

开发者 https://www.devze.com 2022-12-20 15:18 出处:网络
I\'ve inherited an existing php web site.The file names end with the php extension and the code appears to be php.

I've inherited an existing php web site. The file names end with the php extension and the code appears to be php.

Just开发者_运维知识库 wondering why the opening file declaration is "<?" instead of "<?php".

What is the difference between the 2 and why would one be used over the other.

Thanks!


It's called PHP short tags. If short tags is enabled the two notations are equivalent, but short tags can be disabled on some servers so it's usually best to write the tag in full in you are in doubt.

The documentation has this to say:

short_open_tag boolean

Tells 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 <?xml ?> 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 ?>).


<? is 3 fewer characters to type, but will be ambiguous in an XML document (<?xml version="1.0"?> will cause a parse error) and if the short_tags setting is off, it won't work. There's also <?= as a shortcut for <?php echo


This are short tag, i recommend not to use it. There are a lot of them like <script type="php"></script> or asp like <% %> But i recommend to use the <?php ?> style :-)

0

精彩评论

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