<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[沧海一粟]]></title> 
<link>http://www.dzhope.com/index.php</link> 
<description><![CDATA[Web系统架构与服务器运维,php开发]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[沧海一粟]]></copyright>
<item>
<link>http://www.dzhope.com/post//</link>
<title><![CDATA[利用PHP扩展trie_filter做敏感词过滤]]></title> 
<author>jed &lt;jed521@163.com&gt;</author>
<category><![CDATA[服务器技术]]></category>
<pubDate>Sat, 22 Oct 2016 12:24:08 +0000</pubDate> 
<guid>http://www.dzhope.com/post//</guid> 
<description>
<![CDATA[ 
	转自：<a href="http://flyer0126.iteye.com/blog/1931212" target="_blank">http://flyer0126.iteye.com/blog/1931212</a><br/><br/>早就想研究下敏感词过滤问题，今天有些时间，正好实践一下。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1. 安装：libdatrie (<a href="http://linux.thai.net/~thep/datrie/datrie.html#Download)" target="_blank">http://linux.thai.net/~thep/datrie/datrie.html#Download)</a><br/><div class="code"><br/> tar zxf libdatrie-0.2.4.tar.gz <br/> cd libdatrie-0.2.4 <br/> ./configure --prefix=/usr/local <br/> make <br/> make install<br/></div><br/><br/>2. 安装 trie_filter 扩展 (<a href="https://code.google.com/p/as3chat/downloads/detail?name=trie_filter-2011-03-21.tar.gz)" target="_blank">https://code.google.com/p/as3chat/downloads/detail?name=trie_filter-2011-03-21.tar.gz)</a><br/><div class="code"><br/> tar zxf trie_filter-2011.03.21.tar.gz <br/> cd trie_filter-2011.03.21 <br/> phpize （#/usr/local/php/bin/phpize ） <br/> ./configure --with-php-config=/usr/local/php/bin/php-config <br/> make <br/> make install <br/></div><br/><br/>3. 修改 php.ini 文件，添加 trie_filter 扩展：extension=trie_filter.so，重启PHP。<br/>&nbsp;&nbsp; 查看phpinfo发现trie_filter 扩展可用，如下图所示：<br/><a href="http://www.dzhope.com/attachment.php?fid=79" target="_blank"><img src="http://www.dzhope.com/attachment.php?fid=79" class="insertimage" alt="点击在新窗口中浏览此图片" title="点击在新窗口中浏览此图片" border="0"/></a><br/> 4. 生成敏感词词典 （dpp 在 trie_filter-1.0.0 里面）<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;将需要检测的敏感词写入一文本文件（如：mgc.txt），每行一个敏感词，然后使用dpp处理文本文件生成词典。<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;规则：./dpp txt_file_path dict_file_path <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;示例：./dpp ～/mgc.txt mgc.dic <br/> <br/>5. 应用<br/><div class="code"><br/>&lt;?php<br/>/**<br/> * trie_filter 敏感词过滤示例<br/> * <br/> * @author flyer0126<br/> * @since&nbsp;&nbsp;2013/08/26<br/> **/<br/><br/>// 载入词典，成功返回一个 Trie_Filter 资源句柄，失败返回 NULL<br/>$file = trie_filter_load(&#039;/usr/local/src/trie_filter/mgc.dic&#039;);<br/>var_dump($file);<br/>$str1 = &#039;今天利用trie_filter做敏感词过滤示例&#039;;<br/>$str2 = &#039;今天利用trie_filter做过滤示例&#039;;<br/>// 检测文本中是否含有词典中定义的敏感词(假设敏感词设定为：‘敏感词’)<br/>$res1 = trie_filter_search($file, $str1);<br/>$res2 = trie_filter_search($file, $str2);<br/>echo $res1 ? &#039;存在敏感词&#039; : &#039;不存在敏感词&#039;;<br/>echo &quot;&lt;br/&gt;&quot;;<br/>echo $res2 ? &#039;存在敏感词&#039; : &#039;不存在敏感词&#039;;<br/><br/>/**<br/>resource(1) of type (Trie tree filter)<br/>存在敏感词<br/>不存在敏感词<br/>**/<br/></div><br/><br/>&nbsp;&nbsp; 对应 libdatrie-0.2.4.tar.gz 及 trie_filter-2011-03-21.tar.gz 已添加至附件中，有兴趣的可以拿走～<br/><br/><a href="attachment.php?fid=80">点击这里下载文件</a><br/><a href="attachment.php?fid=81">点击这里下载文件</a>
]]>
</description>
</item><item>
<link>http://www.dzhope.com/post//#blogcomment</link>
<title><![CDATA[[评论] 利用PHP扩展trie_filter做敏感词过滤]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.dzhope.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>