snipe / banbuilder

Composer package for censoring profanity in web applications, forums, etc.
http://www.banbuilder.com
327 stars 99 forks source link

Replace bad word with string rather than character #22

Open stephan10 opened 9 years ago

stephan10 commented 9 years ago

Would it be possible to make it so that if the replacer is a string, the bad word will be replaced by the string

for example if the replacer is set to "[censored]"

"go to hell." would turn into "go to [censored]."

Thanks

Aloria530 commented 8 years ago

Try this:

use Snipe\BanBuilder\CensorWords;
$censor = new CensorWords;
$yourstring = 'Go to hell, you b1tch!';
$string = $censor->censorString($yourstring);
$filteredText= (!empty($string['matched'])) ? str_replace($string['matched'], "[censored]", $string['orig']) : $string['orig'];

// returns "Go to [censored], you [censored]!"
echo $filteredText;

$string['matched'] returns an array of the bad words found. You can "str_replace" this returned array.