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\Sentinel\Facades\Sentinel;
// Check if text contains offensive content
$isOffensive = Sentinel::offensive('some text');
// Get cleaned version of text
$cleanText = Sentinel::clean('some text');
// Get detailed analysis with sentiment and matches
$result = Sentinel::check('some text');
// Use a specific provider
$result = Sentinel::with(Provider::Prism, 'some text');
// Check if text is offensive
$isOffensive = is_offensive('some text');
// Clean offensive content
$cleanText = clean('some text');
$rules = [
'comment' => ['
use Ninja\Sentinel\Enums\Provider;
$result = Sentinel::with(Provider::Local, 'text to check');
$result = Sentinel::with(Provider::PurgoMalum, 'text to check');
$result = Sentinel::with(Provider::Azure, 'text to check');
$result = Sentinel::with(Provider::Perspective, 'text to check');
$result = Sentinel::with(Provider::Tisane, 'text to check');
use Ninja\Sentinel\Enums\Provider;
$result = Sentinel::with(Provider::Prism, 'text to check');
$result = Sentinel::check('some text');
// Basic information
$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(); // Score: offensive content score
$result->confidence(); // Confidence: confidence level
// Detailed analysis
$result->sentiment(); // Sentiment: text sentiment analysis
$result->categories(); // array: detected content categories
// Match information
$result->matches(); // MatchCollection: detailed matches with positions
$matches = $result->matches();
foreach ($matches as $match) {
echo "Word: " . $match->word();
echo "Type: " . $match->type(); // exact, pattern, variation, etc.
echo "Score: " . $match->score();
echo "Confidence: " . $match->confidence();
// Get all occurrences of the match
foreach ($match->occurrences() as $occurrence) {
echo "Position: " . $occurrence->start();
echo "Length: " . $occurrence->length();
}
// Context information if available
if ($context = $match->context()) {
echo "Original form: " . $context['original'];
echo "Surrounding text: " . $context['surrounding'];
}
}
use Ninja\Sentinel\Enums\Category;
$categories = $result->categories();
// Can Category::Violence
// - Category::Threat
// - Category::Toxicity
// - Category::Profanity