PHP code example of taoran / filter-word

1. Go to this page and download the library: Download taoran/filter-word 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/ */

    

taoran / filter-word example snippets


$filter = new Filter();
$filter->dict->setDictFile(BASE_PATH . '/public/dict/', 'dict.php');
$result = $filter->filter($text);    //return bool: true 表示有敏感词

$dict = new Dict();
//设置词库文件两个参数: 路径和文件
$dict->setDictFile(BASE_PATH . '/public/dict/', 'dict.php');
// 添加词汇
$addResult = $dict->add(['词汇一', '词汇二', '词汇五']);
// 删除词汇
$delResult = $dict->destroy(['词汇一']);
// 获取词库内容
$dictContent = $dict->getDictContent();
// 获取词库节点树
$dictDFAContent = $dict->getDictDFAContent();