• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

php敏感词过滤使用第三方扩展trie_filter

php 搞代码 4年前 (2022-01-04) 31次浏览 已收录 0个评论

安装

ubuntu 14.04

安装 libdatrie

// sudo apt-get install libdatrie-dev

安装 trie_filter 扩展

> git clone  > cd php-ext-trie-filter> phpize> ./configure --with-php-config=/usr/bin/php-config> make> make install//添加php扩展,extension=trie_filter.so> service php5-fpm  restart> php5-fpm -m //查看

使用

生成敏感词库

 $arrWord = array('word1', 'word2', 'word3');   $resTrie = trie_filter_new(); //create an empty trie tree  foreach ($arrWord as $k => $v) {      trie_filter_store($resTrie, $v);  }  trie_filter_save($resTrie, __DIR__ . '/blackword.tree');  trie_filter_free($resTrie);

使用

$resTrie = trie_filter_load(__DIR__ . '/blackword.tree');    $strContent = 'hello word2 word1';    $arrRet = trie_filter_search($resTrie, $strContent);    print_r($arrRet); //Array(0 => 6, 1 => 5)    echo substr($strContent, $arrRet[0], $arrRet[1]); //word2    $arrRet = trie_filter_search_all($resTrie, $strContent);    print_r($arrRet); //Array(0 => Array(0 => 6, 1 => 5), 1 => Array(0 => 12, 1 => 5))    foreach ($arrRet as $item) {        echo substr($strContent, $item[0], $item[1]); //word2 word1    }    $arrRet = trie_filter_search($resTrie, 'hello word');    print_r($arrRet); <strong style="color:transparent">来源gaodai#ma#com搞@代~码网</strong>//Array()    trie_filter_free($resTrie);

以上就是php敏感词过滤使用第三方扩展trie_filter的内容,更多相关内容请随时关注我们网站!

相关文章:

一个高效的敏感词过滤方法(PHP)

利用PHP扩展trie_filter做中文敏感词过滤

PHP实现过滤留言信息中的敏感词


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:php敏感词过滤使用第三方扩展trie_filter

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址