Word Filter

A

Anonymous

Guest
Alright well ive searched these forums and couldnt find a post on making a word filter...

right now the way i have my word filter going is by using

$msg = str_replace(array("word1", "word2", "word3"), "****", $msg);

which works i guess, but i want a more accurate word filter, i mean is their anyway of doing something like...

say that

$msg = "you XxxxX ok ZzzZ"

XxxxX and ZzzZ are the words that are needed to be filtered out, is their any way to search for XxxxX as well as ZzzZ, and have it pull each of the words out individually so that they could be converted to X***X and Z**Z...that's basically what i want to do but im thinking i might be overthinking this one...
 
GostLy said:
XxxxX and ZzzZ are the words that are needed to be filtered out, is their any way to search for XxxxX as well as ZzzZ, and have it pull each of the words out individually so that they could be converted to X***X and Z**Z...that's basically what i want to do but im thinking i might be overthinking this one...

str_replace can accept an array for the second argument as well, so you'd want to do this:

Code:
<?php
$msg = str_replace(array("XxxxX", "ZzzZ"), array('X***X', 'Z**Z'), $msg);
?>
 
wow, i didnt even think of that, worked out nicely, thanks alot
 
Back
Top