0

我正在使用一个非常简单的代码

<? if ($_GET["end"]=='1') { ?>
    <div id="header-message">
        this is the message
    </div>
<?  } ?>  

在我的公司服务器中,代码被忽略,浏览器显示 DIV

在我的个人服务器上,除非变量 $end 是 !="" 否则不会显示消息

我很难过什么会导致这个问题...是 phph 5.3.3 和 5.4 的区别吗?要不然?或者可能代码是错误的?

4

3 回答 3

2

很可能是因为您缺少phpphp 标记的部分。

<? if ($_GET["end"]=='1') { ?>
    <div id="header-message">
        this is the message
    </div>
<?  } ?> 

变成

<?php if ($_GET["end"]=='1') { ?>
    <div id="header-message">
        this is the message
    </div>
<?php  } ?> 

更新

正如其他人所说,如果您启用了short_open_tag指令,则第一个选项是有效的。另请注意,从 PHP 5.4.0 开始,您不需要指定 short_open_tag 指令。

于 2013-03-15T20:33:45.820 回答
0

1表示true但“1”是一个string'1'。所以你使用 only 1or truefor 检查是真的。

并使用完整标签<?php ... ?>而不是短标签<? ... ?>

于 2013-03-15T20:38:22.137 回答
0

试试这个: if ($_GET["end"]==1) 而不是 '1'.. 如果你的 php.ini 允许短标签,他的代码也应该使用。

Maybe 在一个 case 中被读取为整数,在另一个 case 中被读取为 string。

于 2013-03-15T20:36:29.300 回答