是否可以用 php 找出短的开始标志<?
在脚本中是否足够?
是否有 ini 变量,或者我是否需要使用输出缓冲对某些函数进行编程才能查看结果?
php short_open_tag
.ini打开/关闭<?
。但是,<?=...?>
在最近的 PHP 版本中始终有效。
您可以使用 ini_get()
检索其值 - 但不能使用 ini_set
更改它。不过,您可以使用包含php_flag short_open_tag on
的.htaccess进行设置。
所以你永远不应该对PHP块使用<?
,而应该<?php
。对于表达式<?=
如果您不需要支持古老的 PHP 版本,则可以使用。
是的,有一个 ini 变量,它被称为 short_open_tags
。因此,只需将ini_get
与 sort_open_tags
一起放置,因为如果服务器上有短标签,参数应该返回true
:
ini_get('short_open_tag')
我现在
做了一些仔细检查:
<?php
check_configuration(); // on a blank linux install check for some config flags
function check_configuration(){
$test_short_open_tag=false;
?><? $test_short_open_tag=true; ?><?php
if(!ini_get('short_open_tag') or !$test_short_open_tag){
die( '<br>ERROR: please allow ''short_open_tag'' in php.ini or .htaccess to allow the use of "<?"<br><br>');
}
}