2014-12-06 47 views
-1

對於例>內容=樹返回的特殊內容,以樹建立一個屬性是否

含量爲>的index.php內容=樹

<?php 
if (<?= $_GET['content'] ?> == tree) { 
echo "text here"; 
} 
else { 
echo "nothing to see here"; 
} 
?> 
+1

刪除此標籤:''也把像' 「樹」 引號''tree'是 – Rizier123 2014-12-06 16:08:51

+2

它的JavaScript或PHP? – GolezTrol 2014-12-06 16:10:39

回答

0

首先,我建議你檢查的PHP的手動功能和其他的PHP代碼,這裏有一個例子的,如果/ ELSEIF/else語句:link

現在,在你的代碼,你這樣做:if (<?= $_GET['content'] ?> == tree) {

注意你怎麼叫php echo <?= $_GET['content'] ?> == tree作爲一個條件,首先出現錯誤,因爲你不能調用php作爲條件,更不用說回聲了。 你這是怎麼應該寫的代碼:

<?php 

    if ($_GET['content'] == 'tree') { 

     echo "text here"; 

    } 
    else { 

     echo "nothing to see here"; 

    } 

?> 

請看看我給你的鏈接。

2

搞掂:

<?php 
if (isset($_GET['content']) && $_GET['content'] == 'tree') { 
echo "text here"; 
} 
else { 
echo "nothing to see here"; 
} 
?> 

倍數:

<?php 
if (isset($_GET['content']) && in_array($_GET['content'], array('tree', 'bird', 'fish', 'taco'))) { 
echo "text here"; 
} 
else { 
echo "nothing to see here"; 
} 
?> 
+2

應該明智地包含'isset($ _ GET ['content'])''。否則,它會拋出警告 – DarkBee 2014-12-06 16:14:38

+1

真,感謝趕上@DarkBee – xtrman 2014-12-06 16:19:08

+0

isset($ _ GET [ '內容'])&& $ _GET [ '內容'] == '樹' 壽:) – DarkBee 2014-12-06 16:21:16

相關問題