2013-03-15 31 views
0

我在我的公司服務器使用非常簡單的代碼PHP 5.3.3是否會忽略我的代碼或什麼?

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

代碼被忽略,瀏覽器顯示我的個人服務器上的DIV

除非變量$到底是不顯示的消息!=「」

我有困難時間什麼可以導致這個問題......是phph 5.3.3 vs 5.4的區別?要不然?或者可能代碼錯誤?

+3

你有沒有試圖改變'<?''到<?php'? – j08691 2013-03-15 20:33:43

+0

公司服務器上是否啓用了PHP?在瀏覽器中查看生成頁面的源代碼,如果您仍然看到「<?」,那麼它不會被解析。 – 2013-03-15 20:33:48

+0

檢查您的['short_open_tag'](http://us.php.net/manual/en/ini.core.php#ini.short-open-tag)設置。 – DCoder 2013-03-15 20:34:06

回答

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 } ?> 

UPDATE

正如其他人所指出的,第一個選項是有效的,如果你對short_open_tag指令。請注意,從PHP 5.4.0開始,您不需要指定short_open_tag指令。

+0

第一種是可接受的語法,但它需要'short_open_tag'開啓。 – ceejayoz 2013-03-15 20:35:18

+0

@ceejayoz謝謝。我用鏈接和解釋更新了答案。 – Kyle 2013-03-15 20:39:10

0

試試這個:if($ _GET [「end」] == 1)而不是'1'..如果你的php.ini允許短標籤,他的代碼也應該可以工作。

也許在一個案例中讀爲整數,在另一個案例中作爲字符串讀取。

0

1表示true但「1」是string'1'。因此,您只使用1true進行檢查。

並使用完整的標籤而不是<?php ... ?><? ... ?>

相關問題