PHP code example of cledilsonweb / badwords

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

    

cledilsonweb / badwords example snippets


    $dictionary = new \Badword\Dictionary\Php('path/to/dictionary_list.php');
    $config = new \Badword\Filter\Config\Standard();
    $filter = new \Badword\Filter($dictionary, $config);

    $result = $filter->filter('My content...');
    $result->getRiskLevel();
    $result->getMatches();
    $result->getMatchesAndRiskLevels();
    $result->getHighlightedContent();

    // An example moderate dictionary.
    $dictionaryWords = array(
        'some',
        'bad',
        'words'
    );

    $dictionary = new \Badword\Dictionary\PhpArray($dictionaryWords, 1);
    $config = new \Badword\Filter\Config\Standard();
    $filter = new \Badword\Filter($dictionary, $config);

    $result = $filter->filter('My content...');
    $result->getRiskLevel();
    $result->getMatches();
    $result->getMatchesAndRiskLevels();
    $result->getHighlightedContent();

   $dictionaryWords = array(
        'reject' => array(
            'maecenas',
            'mauris',
            'luctus'
        ),
        'moderate' => array(
            'consectetur',
            'neque',
            'velit'
        )
   );
    
   $Badwords = new \Badword\Badwords($dictionaryWords);
    
   $result = $Badwords->Filter()->filter('My content...'));
   $result->getRiskLevel();
   $result->getMatches();
   $result->getMatchesAndRiskLevels();
   $result->getHighlightedContent();