PHP 5.3.3是否忽略了我的代码或什么?

时间:2013-03-15 20:32:06

标签: php

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

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

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

在我的个人服务器上,除非变量$ end是!=“”

,否则不会显示该消息

我很难解决导致这个问题的原因...... phph 5.3.3与5.4相比有什么不同?要不然?或者代码是错的?

3 个答案:

答案 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'。因此,您只能使用1true进行检查。

并使用完整标记<?php ... ?>代替短<? ... ?>