繁体   English   中英

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

[英]String matching in php not working correctly?

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

码:

 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相同stristr($post['message'],$t1)=== TRUE ie; 只给出一个结果〜

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

http://www.php.net/stristr

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

使用stripos,而不是stristr。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM