git clone https://github.com/alytvynov/spam-analyzer
cd spam-analyzer
docker-compose up -d
docker exec -it php_spam-analyzer bash -c "composer install"
composer install
Spam Analyzer is a simple class that allows you to detect and replace
- bad words
- sites
- phone numbers
Use : SpamAnalyser.php
use Ltv\Service\SpamAnalyzer;
$text = 'Il est con, non ? détenté +33 6 60 58 74 74 conçue con [email protected] first.com second.org Con lorem ipsum';
$spamAnalyzer = (new SpamAnalyzer($text))->process();
$ta->getOutput();
'Il est <red>con</red>, non ? détenté <phone>+33 6 60 58 74 74</phone> conçue <red>con</red> <email>[email protected]</email> <site>first.com</site> <site>second.org</site> <red>con</red> lorem ipsum',
$spamAnalyzer->getProcessResult()
[
"insults" => [
0 => "con"
],
"emails" => [
0 => "[email protected]"
],
"phones" => [
0 => "+33 6 60 58 74 74"
],
"sites" => [
0 => "first.com",
1 => "second.org"
]
];
To change the html replacement you can find constants
const HTML_FORMAT_INSULT_WORDS = '<red>%s</red>';
const HTML_FORMAT_RACIST_WORDS = '<red>%s</red>';
const HTML_FORMAT_ALERT_WORDS = '<orange>%s</orange>';
const HTML_FORMAT_SERVICES_WORDS = '<blue>%s</blue>';
const HTML_FORMAT_ACTIVITIES_WORDS = '<green>%s</green>';
And the mapping :
const MAPPING = [
self::KEY_INSULT_WORDS => self::HTML_FORMAT_INSULT_WORDS,
...
$spamAnalyzer = (new SpamAnalyzer($text))
->setBadWords(
[
'words' => [
'grey water',
'showers',
'water',
'dog',
],
]
)->process();
composer install #install php unit dependencies
./vendor/bin/phpunit --verbose --bootstrap vendor/autoload.php tests;
- Anton LYTVYNOV
- Site
- [email protected]