php-ext-trie-filter
===================
php extension for spam word filter based on Double-Array Trie tree, it can detect if a spam word exists in a text message.
关键词过滤扩展,用于检查一段文本中是否出现敏感词,基于Double-Array Trie 树实现。
## 升级历史
### 2017-08-08
1. 同时支持php5&php7
1. 新增方法:
1. trie_filter_read,从string中读取二进制字典数据
1. trie_filter_write,将当前对象导出成二进制string
1. trie_filter_delete,从当前对象中删除一个word
### 2013-06-23
1. trie_filter_search_all,一次返回所有的命中词
1. 修复内存泄露
## 依赖库
[libdatrie-0.2.4 or later](http://linux.thai.net/~thep/datrie/datrie.html)
## 安装步骤
下面的$LIB_PATH为依赖库安装目录,$INSTALL_PHP_PATH为PHP安装目录。
### 安装libdatrie
```
$ tar zxvf libdatrie-0.2.4.tar.gz
$ cd libdatrie-0.2.4
$ make clean
$ ./configure --prefix=$LIB_PATH
$ make
$ make install
```
### 安装扩展
```
$ $INSTALL_PHP_PATH/bin/phpize
$ ./configure --with-php-config=$INSTALL_PHP_PATH/bin/php-config --with-trie_filter=$LIB_PATH
$ make
$ make install
```
然后修改php.ini,增加一行:extension=trie_filter.so,然后重启PHP。
## 使用示例
```
<?php
$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');
$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))
$arrRet = trie_filter_search($resTrie, 'hello word');
print_r($arrRet); //Array()
trie_filter_free($resTrie);
```
# PHP版本
PHP 5.2 ~ 7.1.
Windows is not support until now.
## License
Apache License 2.0
## 致谢
本项目是在[用于检测敏感词的 PHP 扩展](http://blog.anbutu.com/php/php-ext-trie-filter)的基础上改写的。
基于Double-Array Trie树的垃圾邮件过滤器的 php扩展,它可以检测文本消息中是否存在垃圾邮件_C语言php
版权申诉
5星 · 超过95%的资源 49 浏览量
2022-07-12
20:14:32
上传
评论
收藏 9KB ZIP 举报
快撑死的鱼
- 粉丝: 1w+
- 资源: 9156
最新资源
- 3122080306 邹子轩 实验报告二.docx
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发)(大赛作品,文档完整,可直接运行)
- 发那科工业机器人保养大全
- Sphere.h
- REMD固有时间尺度分解信号分量可视化(Matlab完整源码和数据)
- 嵌入式系统双单片机STC89C52+STC15W104多功能学习板电路图可扩展 适用于单片机初学者和教学
- 基于STM32蓝牙控制小车系统设计(硬件+源代码+论文)大赛作品
- XILINXFPGA源码基于Spartan3火龙刀系列FPGA开发板VGA测试例程
- Java聊天室的设计与实现【尚学堂·百战程序员】
- python中matplotlib教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈