php中的字符串匹配无法正常工作?

时间:2013-12-18 23:56:49

标签: php string

stristr($post['message'],$t1)=== FALSE给出了结果列表,但我需要stristr($post['message'],$t1)=== TRUE,只能得到1个结果! 帮助PLZ。,

CODE:

 foreach($page_posts['data'] as $post){
        if(!(stristr($post['message'],$t1)=== FALSE) && $t1!==" ")
        { 
        $message = (($post['message']) ? $post['message'] : " ");
        $i++;
        print($message);
        }

stristr($post['message'],$t1)=== TRUE相同,即;仅给出一个结果〜

2 个答案:

答案 0 :(得分:2)

stristr不会返回布尔值TRUE ...当找到您要查找的字符串时,它将返回字符串。否则,它将返回布尔值FALSE。

http://www.php.net/stristr

用stristr测试($ post ['message'],$ t1)=== TRUE是错误的。

答案 1 :(得分:0)

使用stripos,而不是stristr。

if(stripos($post['message'], $t1) > -1) {
  // needle is in haystack
}