helraizer Posted November 23, 2007 Share Posted November 23, 2007 Hi folks, I have a piece of code: $dirty = array('bad words here', 'more bad words here', 'this is another bad word'); foreach($dirty AS $bad_word){ $text = preg_replace("/$bad_word/i","****", $text); } Which works fine but how would I do it so that instead of replacing it with **** it merely gets rid of it completely? Hope that makes sense, Sam Quote Link to comment Share on other sites More sharing options...
toplay Posted November 23, 2007 Share Posted November 23, 2007 change "****" to empty string "". Quote Link to comment Share on other sites More sharing options...
Orio Posted November 23, 2007 Share Posted November 23, 2007 And you should use str_ireplace() instead of preg_replace(). Much faster. Orio. Quote Link to comment Share on other sites More sharing options...
effigy Posted November 27, 2007 Share Posted November 27, 2007 Always preg_quote variables that are going to be used in regular expressions. 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.