PHP code example of diego-ninja / laravel-censor

1. Go to this page and download the library: Download diego-ninja/laravel-censor 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/ */

    

diego-ninja / laravel-censor example snippets


use Ninja\Censor\Facades\Censor;

// Check if text contains offensive content
$isOffensive = Censor::offensive('some text');

// Get cleaned version of text
$cleanText = Censor::clean('some text');

// Get detailed analysis
$result = Censor::check('some text');

// Check if text is offensive
$isOffensive = is_offensive('some text');

// Clean offensive content
$cleanText = clean('some text');

$rules = [
    'comment' => ['

use Ninja\Censor\Enums\Service;

$result = Censor::with(Service::Local, 'text to check');

$result = Censor::with(Service::PurgoMalum, 'text to check');

$result = Censor::with(Service::Azure, 'text to check');

$result = Censor::with(Service::Perspective, 'text to check');

$result = Censor::with(Service::Tisane, 'text to check');

$result = Censor::check('some text');

$result->offensive();    // bool: whether the text contains offensive content
$result->words();        // array: list of matched offensive words
$result->replaced();     // string: text with offensive words replaced
$result->original();     // string: original text
$result->score();        // ?float: offensive content score (if available)
$result->confidence();   // ?float: confidence level (if available)
$result->categories();   // ?array: detected categories (if available)

    'cache' => [
        'enabled' => env('CENSOR_CACHE_ENABLED', true),
        'store' => env('CENSOR_CACHE_STORE', 'file'),
        'ttl' => env('CENSOR_CACHE_TTL', 60),
    ],

// resources/dict/custom.php
return [
    'word1',
    'word2',
    // ...
];

// config/censor.php
'languages' => ['en', 'custom'],

// config/censor.php
'whitelist' => [
    'word1',
    'word2',
],

// config/censor.php
'replacements' => [
    'a' => '(a|@|4)',
    'i' => '(i|1|!)',
    // ...
],
bash
php artisan vendor:publish --tag="censor-config"
php artisan vendor:publish --tag="censor-dictionaries"