2014-12-06 42 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

相关问题