<?php
function keyWordCheck($str){
// 去除空白
$str = trim($str);
// 读取关键字文本
$content = @file_get_contents('000.txt');
// 转换成数组
$arr = explode("\n", $content);
// var_dump($arr);
// 遍历检测
for($i=0,$k=count($arr);$i<$k;$i++){
// 如果此数组元素为空则跳过此次循环
if($arr[$i]==''){
continue;
}
// 如果检测到关键字,则返回匹配的关键字,并终止运行
if(strpos($str,trim($arr[$i]))!==false){
return $arr[$i];
}
}
// 如果没有检测到关键字则返回false
return false;
}
$content = '王涵万';
if ( keyWordCheck($content) ){
echo "存在关键字! ";
}else{
echo "不存在关键字! ";
}
?>