Skip to content

Instantly share code, notes, and snippets.

@valdiney
Created March 21, 2015 19:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valdiney/bd9138c4dbb31f0717ef to your computer and use it in GitHub Desktop.
Save valdiney/bd9138c4dbb31f0717ef to your computer and use it in GitHub Desktop.
Filtro de palavras
<?php
/**
* Classe palavras restritas: Uma classe que funciona como um filtro,
* recebendo um 'texto' e um 'array' com palavras que serão filtradas.
* @author Valdiney França <valdiney.2@hotmail.com>
* @version 0.1
*/
class Restrict
{
protected static $normalText;
protected static $prohibitedWords;
protected static $character = "###";
public static function setNormalText($text)
{
self::$normalText = $text;
return new self;
}
public static function setProhibited(Array $words)
{
self::$prohibitedWords = $words;
return new self;
}
public static function setCharacter($character)
{
self::$character = $character;
return new self;
}
public static function restricting()
{
$allocateText = array();
for ($cont = 0; $cont < strlen(self::$normalText); $cont++)
{
$allocateText[] = self::$normalText;
}
foreach ($allocateText as $list)
{
return str_replace(self::$prohibitedWords, self::$character, $list);
}
}
}
?>
<?php
$palavrasProibidas = array('puta','Puta','PUTA',
'viado','Viado','VIADO',
'cu','Cu','CU',
'boceta','Boceta','BOCETA',
'corno','Corno','CORNO',
'foda','Foda','FODA');
$texto = "
Boceta puta O nível de stress de uma pessoa é inversamente proporcional à quantidade de foda-se! que ela diz.
Existe algo mais libertário do que o conceito do foda-se!?
O foda-se! aumenta a minha auto-estima, torna-me uma pessoa melhor.
Reorganiza as coisas. Liberta-me.
";
Restrict::setNormalText($texto)
->setProhibited($palavrasProibidas)
->setCharacter("***");
echo Restrict::restricting();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment