{"id":13699905,"url":"https://github.com/wulijun/php-ext-trie-filter","last_synced_at":"2025-05-04T18:33:51.608Z","repository":{"id":4120237,"uuid":"5231071","full_name":"wulijun/php-ext-trie-filter","owner":"wulijun","description":"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 树实现。","archived":false,"fork":false,"pushed_at":"2024-05-30T08:32:42.000Z","size":24,"stargazers_count":514,"open_issues_count":12,"forks_count":169,"subscribers_count":38,"default_branch":"master","last_synced_at":"2024-11-13T06:32:49.023Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wulijun.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2012-07-30T10:33:06.000Z","updated_at":"2024-05-27T16:46:36.000Z","dependencies_parsed_at":"2024-11-18T07:13:35.998Z","dependency_job_id":null,"html_url":"https://github.com/wulijun/php-ext-trie-filter","commit_stats":{"total_commits":18,"total_committers":6,"mean_commits":3.0,"dds":"0.38888888888888884","last_synced_commit":"78b4c04750c9dbe7f6868c81179af435893634bd"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wulijun%2Fphp-ext-trie-filter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wulijun%2Fphp-ext-trie-filter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wulijun%2Fphp-ext-trie-filter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wulijun%2Fphp-ext-trie-filter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wulijun","download_url":"https://codeload.github.com/wulijun/php-ext-trie-filter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252382797,"owners_count":21739216,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T20:00:45.565Z","updated_at":"2025-05-04T18:33:51.300Z","avatar_url":"https://github.com/wulijun.png","language":"C","funding_links":[],"categories":["数据转换","C"],"sub_categories":[],"readme":"php-ext-trie-filter\n===================\n\nphp extension for spam word filter based on Double-Array Trie tree, it can detect if a spam word exists in a text message.\n\n关键词过滤扩展，用于检查一段文本中是否出现敏感词，基于Double-Array Trie 树实现。\n\n## 升级历史\n\n### 2017-08-08\n1. 同时支持php5\u0026php7\n1. 新增方法:\n  1. trie_filter_read，从string中读取二进制字典数据\n  1. trie_filter_write，将当前对象导出成二进制string\n  1. trie_filter_delete，从当前对象中删除一个word\n\n### 2013-06-23\n1. trie_filter_search_all，一次返回所有的命中词\n1. 修复内存泄露\n\n## 依赖库\n\n[libdatrie-0.2.4 or later](http://linux.thai.net/~thep/datrie/datrie.html)\n\n## 安装步骤\n\n下面的$LIB_PATH为依赖库安装目录，$INSTALL_PHP_PATH为PHP安装目录。\n\n### 安装libdatrie\n```\n$ tar zxvf libdatrie-0.2.4.tar.gz\n$ cd libdatrie-0.2.4\n$ make clean\n$ ./configure --prefix=$LIB_PATH\n$ make\n$ make install\n```\n### 安装扩展\n```\n$ $INSTALL_PHP_PATH/bin/phpize\n$ ./configure --with-php-config=$INSTALL_PHP_PATH/bin/php-config --with-trie_filter=$LIB_PATH\n$ make\n$ make install\n```\n然后修改php.ini，增加一行：extension=trie_filter.so，然后重启PHP。\n\n## 使用示例\n```\n\u003c?php\n$arrWord = array('word1', 'word2', 'word3');\n$resTrie = trie_filter_new(); //create an empty trie tree\nforeach ($arrWord as $k =\u003e $v) {\n    trie_filter_store($resTrie, $v);\n}\ntrie_filter_save($resTrie, __DIR__ . '/blackword.tree');\n\n$resTrie = trie_filter_load(__DIR__ . '/blackword.tree');\n\n$strContent = 'hello word2 word1';\n$arrRet = trie_filter_search($resTrie, $strContent);\nprint_r($arrRet); //Array(0 =\u003e 6, 1 =\u003e 5)\necho substr($strContent, $arrRet[0], $arrRet[1]); //word2\n$arrRet = trie_filter_search_all($resTrie, $strContent);\nprint_r($arrRet); //Array(0 =\u003e Array(0 =\u003e 6, 1 =\u003e 5), 1 =\u003e Array(0 =\u003e 12, 1 =\u003e 5))\n\n$arrRet = trie_filter_search($resTrie, 'hello word');\nprint_r($arrRet); //Array()\n\ntrie_filter_free($resTrie);\n```\n# PHP版本\n\nPHP 5.2 ~ 7.1.\n\nWindows is not support until now.\n\n## License\n\nApache License 2.0\n\n## 致谢\n\n本项目是在[用于检测敏感词的 PHP 扩展](http://blog.anbutu.com/php/php-ext-trie-filter)的基础上改写的。\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwulijun%2Fphp-ext-trie-filter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwulijun%2Fphp-ext-trie-filter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwulijun%2Fphp-ext-trie-filter/lists"}