{"id":13814962,"url":"https://github.com/FireLustre/php-dfa-sensitive","last_synced_at":"2025-05-15T06:33:39.803Z","repository":{"id":41377470,"uuid":"95652817","full_name":"FireLustre/php-dfa-sensitive","owner":"FireLustre","description":":see_no_evil: 实现过滤敏感词汇:underage:，基于确定有穷自动机(DFA)算法，支持composer安装扩展","archived":false,"fork":false,"pushed_at":"2022-08-23T15:04:52.000Z","size":59,"stargazers_count":750,"open_issues_count":7,"forks_count":142,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-11-19T10:47:38.573Z","etag":null,"topics":["composer-package","dfa","php","sensitive-word"],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/lustre/php-dfa-sensitive","language":"PHP","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/FireLustre.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}},"created_at":"2017-06-28T09:32:20.000Z","updated_at":"2024-11-04T02:45:09.000Z","dependencies_parsed_at":"2022-08-10T02:06:59.390Z","dependency_job_id":null,"html_url":"https://github.com/FireLustre/php-dfa-sensitive","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FireLustre%2Fphp-dfa-sensitive","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FireLustre%2Fphp-dfa-sensitive/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FireLustre%2Fphp-dfa-sensitive/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FireLustre%2Fphp-dfa-sensitive/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FireLustre","download_url":"https://codeload.github.com/FireLustre/php-dfa-sensitive/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254288967,"owners_count":22045999,"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":["composer-package","dfa","php","sensitive-word"],"created_at":"2024-08-04T04:02:47.724Z","updated_at":"2025-05-15T06:33:39.507Z","avatar_url":"https://github.com/FireLustre.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# php-DFA-filterWord\nphp实现基于确定有穷自动机算法的铭感词过滤 https://packagist.org/packages/lustre/php-dfa-sensitive\n\n##  安装\u0026使用流程\n### Download and install Composer:\n    curl -sS https://getcomposer.org/installer | php\n\u003e 要检查 Composer 是否正常工作，只需要通过 php 来执行 PHAR\n   \n    php composer.phar\n\n### 安装扩展 \n\n    composer require lustre/php-dfa-sensitive\n   \n* 注意:如果你在使用composer安装时，出现                    \n  Could not find package lustre/php-dfa-sensitive at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability 请在你的composer.json中加入\u003ccode\u003e\"minimum-stability\": \"dev\"\u003c/code\u003e\n   \n        \n\n   \n#### 如果你需要手动引入\n\n    require './vendor/autoload.php';\n    \n    use DfaFilter\\SensitiveHelper;\n\n### 构建敏感词库树\n场景一: 可以拿到不同（用户）词库数组\n\n    // 获取感词库索引数组\n    $wordData = array(\n        '察象蚂',\n        '拆迁灭',\n        '车牌隐',\n        '成人电',\n        '成人卡通',\n        ......\n    );\n    \n    // get one helper\n    $handle = SensitiveHelper::init()-\u003esetTree($wordData);\n\n场景二: 全站使用一套敏感词库\n\n    // 获取感词库文件路径\n    $wordFilePath = 'tests/data/words.txt';\n    \n    // get one helper\n    $handle = SensitiveHelper::init()-\u003esetTreeByFile($wordFilePath);\n   \n### 检测是否含有敏感词\n\n    $islegal = $handle-\u003eislegal($content);\n### 敏感词过滤\n    \n    // 敏感词替换为*为例（会替换为相同字符长度的*）\n    $filterContent = $handle-\u003ereplace($content, '*', true);\n    \n     // 或敏感词替换为***为例\n     $filterContent = $handle-\u003ereplace($content, '***');\n     \n ### 标记敏感词\n     $markedContent = $handle-\u003emark($content, '\u003cmark\u003e', '\u003c/mark\u003e');\n    \n### 获取文字中的敏感词\n\n    // 获取内容中所有的敏感词\n    $sensitiveWordGroup = $handle-\u003egetBadWord($content);\n    // 仅且获取一个敏感词\n    $sensitiveWordGroup = $handle-\u003egetBadWord($content, 1);\n\n### 如何使用单元测试进行测试\n#### 安装PHPUnit\n```bash\n$ wget https://phar.phpunit.de/phpunit.phar\n\n$ chmod +x phpunit.phar\n\n$ mv phpunit.phar /usr/local/bin/phpunit\n```\n#### 使用composer自动加载php命名空间\n\n```bash\n$ composer update\n```\n### 运行单元测试\n```bash\n$ phpunit tests/BaseTest.php\n```\n\n*如果大家有更好的建议，请大家多多指正，O(∩_∩)O谢谢*\n\n*你们的star是我的动力*\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFireLustre%2Fphp-dfa-sensitive","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFireLustre%2Fphp-dfa-sensitive","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFireLustre%2Fphp-dfa-sensitive/lists"}