AV1611 Posted October 2, 2008 Share Posted October 2, 2008 ok, I have written a shoutbox that seems to work ok so far. Now I need to make a language filter. I can come up with a word list but what I don't know how to do is make it not "case sensitive". so Frog FROG frOg froG are all the same. Do I need to use preg_replace? I SUCK at regex... Guidance? Thanks. Quote Link to comment Share on other sites More sharing options...
trq Posted October 2, 2008 Share Posted October 2, 2008 You'll be much better of with str_ireplace(). Its amazing what you'll find in the manual. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 2, 2008 Share Posted October 2, 2008 Then just feed it arrays. $str = "There was a big frog which ate the moth. What of the beetle?"; $bad = array("frog","moth","beetle"); echo str_ireplace($bad, "***", $str); Quote Link to comment Share on other sites More sharing options...
AV1611 Posted October 2, 2008 Author Share Posted October 2, 2008 never heard of that command? is that new ? Quote Link to comment Share on other sites More sharing options...
AV1611 Posted October 2, 2008 Author Share Posted October 2, 2008 Ah... I see it's new in PHP5. I haven't done a case insensitive replace in a long time so I guess I didn't ever notice that. I really do try and read the manual Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 2, 2008 Share Posted October 2, 2008 str_ireplace() was added in PHP5. If you are not using PHP5 you could do it like this. $str = "There was a big FrOg which ate the moTH. What of the BeETlE?"; $bad = array("/frog/i","/moth/i","/beetle/i"); echo preg_replace($bad, "***", $str); //OR $bad = array("frog","moth","beetle"); foreach($bad as $word){ $str = preg_replace("#$word#i", str_repeat("*", strlen($word)), $str); } echo $str; Quote Link to comment Share on other sites More sharing options...
trq Posted October 2, 2008 Share Posted October 2, 2008 Ah... I see it's new in PHP5. Sorry, Ive never used anything older than php5 so.... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.