1. Go to this page and download the library: Download krugozor/russian-bad-words 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/ */
krugozor / russian-bad-words example snippets
use Krugozor\RussianBadWords\BadWordsValidator;
use Krugozor\RussianBadWords\Dictionary;
$validator = new BadWordsValidator(Dictionary::profanity());
$result = $validator->check('Ну ты и cyka, блядь!');
$result->isClean(); // false
$result->words(); // ['блядь'] («cyka» это грубая лексика, а не мат: см. уровни словарей)
$result->mask(); // 'Ну ты и cyka, *****!'
$dictionary = Dictionary::profanity()
->merge(Dictionary::profanityRoots())
->merge(Dictionary::rude(), Dictionary::insults());
$validator = new BadWordsValidator($dictionary);
$validator = new BadWordsValidator(Dictionary::stopWords(['drugs', 'weapons', 'extremism']));
$validator = new BadWordsValidator(Dictionary::stopWords()); // все категории
$dictionary = Dictionary::profanity()
->with(['хуяндекс', 'айтиблядь']) // добавить свои слова
->without(['хули']); // убрать слово; оно также не будет находиться по корням
$result = $validator->check($text);
$result->isClean(); // bool
$result->words(); // найденные слова словаря без повторов: ['хуйня', 'блядь']
$result->mask('*'); // текст, где найденные слова заменены звёздочками по числу букв
$result->mask('@', 1, 1); // с открытыми буквами по краям: «хуй» станет «х@й», «блядь» станет «б@@@ь»
$result->occurrences(); // вхождения с позициями
$result->text(); // проверенный текст; смещения вхождений считаются по нему
foreach ($result->occurrences() as $occurrence) {
$occurrence->fragment(); // как написал пользователь: «xуйня»
$occurrence->word(); // слово словаря: «хуйня»; при совпадении по корню нормализованный фрагмент
$occurrence->offset(); // смещение в байтах
$occurrence->length(); // длина в байтах
$occurrence->isByRoot(); // найдено по корню, а не по словарю
}
bash
composer install
composer test # PHPUnit
composer analyse # PHPStan
php console/sample.php # рабочий пример
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.