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 Link to comment https://forums.phpfreaks.com/topic/78560-help-with-preg_replace/ Share on other sites More sharing options...
toplay Posted November 23, 2007 Share Posted November 23, 2007 change "****" to empty string "". Link to comment https://forums.phpfreaks.com/topic/78560-help-with-preg_replace/#findComment-397527 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. Link to comment https://forums.phpfreaks.com/topic/78560-help-with-preg_replace/#findComment-397543 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. Link to comment https://forums.phpfreaks.com/topic/78560-help-with-preg_replace/#findComment-400461 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.