闲者博客 - 跳过 https://bk1314.com/tag/%E8%B7%B3%E8%BF%87/ zh-CN Sun, 06 Mar 2022 00:09:15 +0800 Sun, 06 Mar 2022 00:09:15 +0800 PHP循环判断关键词是否存在,如果存在就跳过 https://bk1314.com/59.html https://bk1314.com/59.html Sun, 06 Mar 2022 00:09:15 +0800 飞鱼 1.设置关键词数组,也可以利用mysql调用得到
$keyword_arr=['关键词1','关键词2','关键词3']

2.建立个子程序方便调用

function checKeyword($str='',$keyword_arr=[]){
    foreach ($keyword_arr as $keyword) {
        if (strstr($str, $keyword) != FALSE)return true;
//如果不需要区别大小写可以这么写
//              if (strstr(strtolower($str), strtolower($keyword)) != FALSE)return true;
    }
    return false;
}

3.调用方式演示

 $strtolowerbt="这里为内容查询这段是否有关键词包含";
if(checKeyword($strtolowerbt,$keyword_arr))
{
 continue;   
}
]]>
0 https://bk1314.com/59.html#comments https://bk1314.com/feed/tag/%E8%B7%B3%E8%BF%87/
PHP循环遇到关键词就跳过分享 https://bk1314.com/46.html https://bk1314.com/46.html Sat, 26 Feb 2022 17:36:47 +0800 飞鱼 $keyword_arr=['词1','词2','词3']; //也可以上面数据库存入 function checKeyword($str='',$keyword_arr=[]){ foreach ($keyword_arr as $keyword) { //var_dump($keyword); if (strstr($str, $keyword) != FALSE)return true; } return false; } while($r = mysql_fetch_array($query)){ $bt=$r['ybt'];//标题 $strtolowerbt=strtolower($bt); if(checKeyword($strtolowerbt,$keyword_arr)) { continue; } } ]]> 0 https://bk1314.com/46.html#comments https://bk1314.com/feed/tag/%E8%B7%B3%E8%BF%87/