Created
March 21, 2015 19:29
-
-
Save valdiney/bd9138c4dbb31f0717ef to your computer and use it in GitHub Desktop.
Filtro de palavras
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 <[email protected]> | |
* @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); | |
} | |
} | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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