日期:2014-05-16  浏览次数:20385 次

strpos函数
<input id="flagc" type ="checkbox" value="c" name="flags[]"<?php if(strpos($row['flag'],'c')=='tuue') echo "checked='checked'" ?>/>推荐[c]
    <input id="flaga" type ="checkbox" value="a" name="flags[]"<?php if(strpos($row['flag'],'a')=='true') echo "checked='checked'" ?>/>特荐[a]
    <input id="flagh" type ="checkbox" value="h" name="flags[]"<?php if(strpos($row['flag'],'h')=='true') echo "checked='checked'" ?>/>头条[h]
    <input id="flago" type ="checkbox" value="o" name="flags[]"<?php if(strpos($row['flag'],'o')=='true') echo "checked='checked'" ?>/>特荐[o]
    <input id="flagn" type ="checkbox" value="n" name="flags[]"<?php if(strpos($row['flag'],'n')=='true') echo "checked='checked'" ?>/>特荐[n]

我想判断$row['flag']是不是c,a,h,o,n其中的一个。加个对勾。这么写为什么只能判断推荐【c】那个啊?后面的都没有显示啊。既然第一个能成功后面的也应该对吧。

------解决方案--------------------
strpos($row['flag'],'c') !== false
------解决方案--------------------
if(strpos($row['flag'],'c') !== false)
其他类同

strpos 返回整数(找不到返回逻辑假)
'true' 在数值比较中被转换为 0
如果 $row['flag'] 第一个字符为 c 时,恰巧被匹配
其他字符返回的都不是 0,所以不会匹配成功