标题:利用PHP扩展trie_filter做敏感词过滤 出处:沧海一粟 时间:Sat, 22 Oct 2016 20:24:08 +0000 作者:jed 地址:http://www.dzhope.com/post/1024/ 内容: 转自:http://flyer0126.iteye.com/blog/1931212 早就想研究下敏感词过滤问题,今天有些时间,正好实践一下。 1. 安装:libdatrie (http://linux.thai.net/~thep/datrie/datrie.html#Download) tar zxf libdatrie-0.2.4.tar.gz cd libdatrie-0.2.4 ./configure --prefix=/usr/local make make install 2. 安装 trie_filter 扩展 (https://code.google.com/p/as3chat/downloads/detail?name=trie_filter-2011-03-21.tar.gz) tar zxf trie_filter-2011.03.21.tar.gz cd trie_filter-2011.03.21 phpize (#/usr/local/php/bin/phpize ) ./configure --with-php-config=/usr/local/php/bin/php-config make make install 3. 修改 php.ini 文件,添加 trie_filter 扩展:extension=trie_filter.so,重启PHP。 查看phpinfo发现trie_filter 扩展可用,如下图所示: 点击在新窗口中浏览此图片 http://www.dzhope.com/attachment.php?fid=79 4. 生成敏感词词典 (dpp 在 trie_filter-1.0.0 里面) 将需要检测的敏感词写入一文本文件(如:mgc.txt),每行一个敏感词,然后使用dpp处理文本文件生成词典。 规则:./dpp txt_file_path dict_file_path 示例:./dpp ~/mgc.txt mgc.dic 5. 应用 "; echo $res2 ? '存在敏感词' : '不存在敏感词'; /** resource(1) of type (Trie tree filter) 存在敏感词 不存在敏感词 **/ 对应 libdatrie-0.2.4.tar.gz 及 trie_filter-2011-03-21.tar.gz 已添加至附件中,有兴趣的可以拿走~ 点击这里下载文件 点击这里下载文件 Generated by Bo-blog 2.1.1 Release