美文网首页
php敏感词过滤使用第三方扩展trie_filter

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

作者: yaokui | 来源:发表于2016-02-19 14:54 被阅读4340次

安装

  • ubuntu 14.04
    • 安装 libdatrie
//http://linux.thai.net/~thep/datrie/datrie.html#Download下不下来,只好直接装
sudo apt-get install libdatrie-dev
  • 安装 trie_filter 扩展
> git clone https://github.com/wulijun/php-ext-trie-filter.git
> 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); //Array()

    trie_filter_free($resTrie);

相关文章

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

    安装 ubuntu 14.04安装 libdatrie 安装 trie_filter 扩展 使用 生成敏感词库 使用

  • python实现敏感词过滤的几种方法

    1.replace过滤 最简单也是最直接的就是直接循环敏感词,然后使用replace过滤关键词,文章和敏感词少的时...

  • 分享几个不错的博客文章

    站点安全之-php内容过滤,敏感词屏蔽,防注入,cookie加密http://www.cnblogs.com/ph...

  • 敏感词过滤算法(2)

    去年写过一篇文章,名字叫做《敏感词过滤算法》,介绍了为什么需要敏感词过滤算法?以及使用什么方式来实现的。其中提到三...

  • 敏感词过滤

    一、原句处理 1.去除原句中的所有空格2.去除原句子中的所有标点符号,包含全角和半角的3.将所有的繁体中文替换成简...

  • go实现敏感词过滤

    敏感词过滤,提前将敏感词设置好,然后每次有新句子都要过滤一遍,若存在敏感词,则用*号代替,代码如下

  • 敏感词过滤器

    使用Decorator模式包装request对象实现敏感字符过滤功能。敏感词包括了:禁用词:反对共产党、色情。。。...

  • 关于评论功能的总结

    作为前端,相对敏感词,我更应该注意对发布内容过滤,js脚本和html标签如何过滤 敏感词的过滤应当是过滤服务器➕人...

  • Zabbix 5.0 LTS监控系统实施

    2:安装 php 7.2 以及 zabbix 所需的 php 扩展模块安装 php 第三方源 yum instal...

  • iOS 敏感词过滤 (OC与Swift版本都有)

    iOS 敏感词过滤:用*代替敏感词 实现效果举例: 敏感词为 : 123 “哈哈123456哈哈123呵呵” 被转...

网友评论

      本文标题:php敏感词过滤使用第三方扩展trie_filter

      本文链接:https://www.haomeiwen.com/subject/gtqvkttx.html