使用xampp进行PHP测试,突然发现PHP不执行了,全是源码输出,后来检查发现,是短标签的问题,因为天缘的习惯一直都是写成<?php and ?>这样的完整形式,但是写成短标签(Short tag)就不可以了,打开PHP.INI文件才知道,原来最新版本的xampp已经默认把短标签只识别支持默认关闭掉了。只需要打开即可。
问题现象:<?php echo "123"; ?>可以执行,<? echo "123"; ?>却直接输出源码。
解决办法:在PHP.INI文件中,查找<?或short_open_tag,有下面信息提示,意思是是否打开短标签识别,而且已经推荐大家使用完整封堵标签<?php and ?>,尽量不要使用短标签<? and ?>。
; 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. ; Default Value: On ; Development Value: Off ; Production Value: Off ; http://php.net/short-open-tag short_open_tag = Off ; Allow ASP-style <% %> tags. ; http://php.net/asp-tags asp_tags = Off
把以上设置short_open_tag = Off改成short_open_tag = On即可,当然asp_tags如果是On要改成Off关闭。
查看更多关于PHP不执行短标签却源码显示输出的问题定位_自学的详细内容...