Skip to content

Spam Analyzer allows you to detect and replace predefined words, emails, sites, phone numbers

License

Notifications You must be signed in to change notification settings

alytvynov/spam-analyzer

Repository files navigation

Spam Analyser

Install

git clone https://github.com/alytvynov/spam-analyzer
cd spam-analyzer

With Docker

docker-compose up -d
docker exec -it php_spam-analyzer bash -c "composer install"

Without Docker

composer install

What is Spam Analyzer ?

Spam Analyzer is a simple class that allows you to detect and replace

  • bad words
  • email
  • sites
  • phone numbers

How to use

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();
Output
$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',
Process result
$spamAnalyzer->getProcessResult()
[
    "insults" => [
        0 => "con"
    ],
    "emails"  => [
        0 => "[email protected]"
    ],
    "phones"  => [
        0 => "+33 6 60 58 74 74"
    ],
    "sites"   => [
        0 => "first.com",
        1 => "second.org"
    ]
];

Colors html

Default html

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,
    ...
Bad words can be set by
$spamAnalyzer = (new SpamAnalyzer($text))
    ->setBadWords(
        [
            'words' => [
                'grey water', 
                'showers', 
                'water', 
                'dog',
            ],
        ]
    )->process();

Tests

composer install #install php unit dependencies
./vendor/bin/phpunit  --verbose --bootstrap  vendor/autoload.php tests;

Contacts

About

Spam Analyzer allows you to detect and replace predefined words, emails, sites, phone numbers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages