tp过滤敏感词

 将该方法放到公共方法文件中,需要过滤敏感词时,直接调用该方法

    /**
	 * 敏感词
	 */
	public function sensitive_words_filter($str)
    {
        // 传入要检查的内容,此处直接定义好,用于测试,正式环境调用该方法传值即可
		$str = '123456falun';
        if (!$str) return '';
        // 敏感词文件位置,可根据自己需求调整
		$file = ROOT_PATH . 'public/static/censorwords/CensorWords';
        $words = file($file);
        foreach ($words as $word) {
            $word = str_replace(array("\r\n", "\r", "\n", "/", "<", ">", "=", " "), '', $word);
            if (!$word) continue;

            $ret = preg_match("/$word/", $str, $match);
            if ($ret) {
                return $match[0];
            }
        }
        return '';
    }

敏感词文件:https://download.csdn.net/download/qq_36611673/86403361,可自行下载

猜你喜欢

转载自blog.csdn.net/qq_36611673/article/details/126401984