PHP code example of gorankrgovic / spam-marker

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

    

gorankrgovic / spam-marker example snippets



use SpamMarker\SpamMarker;

// 1.
// Use some filters
use SpamMarker\Filter\BlackListed;

// 2.
// Initalize the blackisted filter
$blackListed = new BlackListed();

// Add some spammy keywords
$blackListed->add('hacker');
$blackListed->add('attacker');

// 3.
// Initialize the spam marker
$spamMarker = new SpamMarker();

// 4.
// Register the filters
$spamMarker->registerFilter($blackListed);

// 5.
// Check your string against filters
$spamMarkerResult = $spamMarker->check("
	Hello, this is some text containing hacker and attacker 
	and should fail as it has a word that is black-listed
");

// var_dump ( $spamMarkerResult );
// It gives you two objects - is_spam (bool) and messages array

if ( $spamMarkerResult->passed() )
{
    // Do some stuff, because the spam marker is passed
    echo 'Your string doesn\'t contain the spam';
}
else
{
    echo 'String containts the spam!';
}

// If you only want to see if it's failed then just...
if ( $spamMarkerResult->failed() ) {
    // Do stuff
} 



$loadedFilter->setOption('message', 'My own returning error message');



$config = array(
    'message' => 'My own custom error message'
);

$blackListed = new BlackListed($config);



$config = array(
    'dir' => '/path/to/your/folder'
);

$blackListedFile = new BlackListedFile($config);



$config = array(
    'emailsAllowed' => 2
);



$config = array(
    'linksAllowed' => 2,
    'linksRatio' => 20 // Percentage of links to words ratio within the text
);



$config = array(
    'phonesAllowed' => 2
);



$config = array(
    'wordsRatio' => 20 // Percentage of allowed uppercase words in a string
);



interface FilterInterface
    {
        public function filter($data);
    }



array(
    'founded' => true, // or false if spam not found
    'message' => 'message to return if spam found'
);