author:咔咔

 

使用:

 

 /**
* [敏感字过滤]
* @param $content 需要验证的字符串
* @param $verify 是否提示验证
* @return 替换后的内容
*/
function lexVerify($content = '', $verify = false){
if(!$content) return false;
$word = require './word.php'; // 引入敏感字词库
$lexicon = array_combine($word,array_fill(0,count($word),'*')); // 换字符
$str = strtr($content, $lexicon); // 匹配替换
return $str;
}


//获取项目信息
public function insertInfo(){
//公司信息
$companyData = $this->request->param();
if($companyData != ''){
$data['user_id'] = $companyData['user_id'];
$data['companyName'] = $this->lexVerify($companyData['companyName']);
$data['companyType'] = $this->lexVerify($companyData['companyType']);
$data['companyScale'] = $this->lexVerify($companyData['companyScale']);

$product = Db::table('wxb_move_infometion')->insert($data);

if($product){
$send = ['code'=>200,'msg'=>'公司信息添加成功'];
}else{
$send = ['code'=>400,'msg'=>'公司信息添加失败'];
}
$this->result($send,200,'数据初始化成功','json');
}
}

效果

【PHP】特殊词汇过滤_php