我正在使用一个非常简单的代码
<? if ($_GET["end"]=='1') { ?>
<div id="header-message">
this is the message
</div>
<? } ?>
在我的公司服务器中,代码被忽略,浏览器显示DIV
在我的个人服务器上,除非变量$ end是!=“”
,否则不会显示该消息我很难解决导致这个问题的原因...... phph 5.3.3与5.4相比有什么不同?要不然?或者代码是错的?
答案 0 :(得分:2)
最有可能的原因是,您错过了php标记的php
部分。
<? 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指令。
答案 1 :(得分:0)
试试这个:if($ _GET [“end”] == 1)而不是'1'..如果你的php.ini允许短标签,他的代码也可以使用。
可能在一个案例中被读为整数,在另一个案例中被视为字符串。
答案 2 :(得分:0)
1
表示true
,但&#34; 1&#34;是string
或'1'
。因此,您只能使用1
或true
进行检查。
并使用完整标记<?php ... ?>
代替短<? ... ?>