PHP code example of poettian / sensitive-words-filter

1. Go to this page and download the library: Download poettian/sensitive-words-filter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

poettian / sensitive-words-filter example snippets




// 第一个参数数组为 Predis 的连接参数,第二个参数对应上面各个不同的方案[simple|index|participle|dfa]
$filter = new Poettian\Filter\Filter([
    'host' => '192.168.10.10',
    'port' => 6379,
    'password' => 'secret',
], 'dfa');

/*
读取词库文件,写入redis,不传则使用data目录下的词库。当词库较大时,此方法存在性能问题,下面会讲述
此方法只需执行一次
*/
$filter->build('/tmp/sensitive_dict');

// 增加敏感词
$filter->add('敏感词一');
$filter->add('敏感词二');
$filter->add('敏感词三');
//...

// 过滤输入内容
echo $filter->run($content);