设为首页收藏本站

PHP开源论坛

 找回密码
 注册

人人连接登陆

无需注册,直接登录

用新浪微博连接

一步搞定

QQ登录

只需一步,快速开始

查看: 388|回复: 1

敏感词过滤 [复制链接]

Rank: 7Rank: 7Rank: 7

发表于 2012-1-5 16:52:06 |显示全部楼层
  1. /**
  2. * 返回是否含有敏感词
  3. */
  4. function checkWords($text, $filterWords) {
  5.         $text = trim($text);
  6.         $filterWords = preg_replace('/([\[\(\)\]])/' , '\\\${1}' , $filterWords);
  7.         $result = preg_match("/(?:".$filterWords.")/" , $text , $matches);
  8.         return empty($matches)?false:$matches;
  9. }

  10. /**
  11. * 返回包含的所有敏感词
  12. */
  13. function checkWordsM($text, $filterWords) {
  14.         $text = trim($text);
  15.         $filterWords = preg_replace('/([\[\(\)\]])/' , '\\\${1}' , $filterWords);
  16.         $result = preg_match_all("/(?:".$filterWords.")/" , $text , $matches);
  17.         return empty($matches)?false:$matches;
  18. }
复制代码

使用道具 举报

Rank: 7Rank: 7Rank: 7

发表于 2012-1-5 16:54:09 |显示全部楼层
使用方法:
$text = '这是什么网站,PHP开源网吗!';
$filterWords = '你好|开源|一网打尽';

$a = checkWordsM($text, $filterWords);

$b = checkWords($text, $filterWords);
PHP开源网:http://www.php-open.org

使用道具 举报

您需要登录后才可以回帖 登录 | 注册 人人连接登陆

Archiver|手机版|PHP开源网 ( 豫ICP备08005353号 )   

GMT+8, 2012-5-21 02:58

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部