PHP code example of pengyu / dfa-filter

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

    

pengyu / dfa-filter example snippets


    use Pengyu\DfaFilter\Filter;
    

$filter=Filter::build();
$filter->addSensitives(["测试","良好","通过"]);
$filter->importSensitiveFile("words.txt");

$filter->addDisturbance("@");
$filter->addDisturbance(["?","%"]);

$filter->isKey("测试呀");
$filter->isKey("测试");
$filter->isKey("@测?试");

$filter->check("测试呀");
$filter->check("测试通?过了啊,感觉良?好%");
$filter->check("这次通不过了呀");

$filter->filter("测试了一下,看看能不能@@通%%过了","^",Filter::DFA_MAX_MATCH);
$filter->filter("简单的内容测?试,有敏感词");
$filter->filter("有很?多测@@试?的词,能?不能良%好?通??%过呢");

$filter->mark("这里有一个敏感词通过,看看测@试%会不会过");
$filter->mark("这里有一个敏感词通过,看看测@试%会不会过",["<span>","</span>"],Filter::DFA_MAX_MATCH);

$filter->flushSensitives();
$filter->flushDisturbance();

$filter->getSensitivesTree();
$filter->getDisturbance();
shell script
php run.php