Forum Moderators: coopster
I got this function from somewhere else:
$var = "somesomesome and in somesomei I somie, some. someone .some";
$badword = "some";
$var = preg_replace(array("/([\W]+){$badword}([\W]+)/","/([\W]+){$badword}([\W]+)/"),$1?.str_repeat("*",strlen($badword)).$2?,$var);
This is to remove word from a string but that word SHOULD not be a part of any word.. for example if i want to remove "some" then "someone" should be left as it is..
BUT this function is not working properly.. can anybody take a look and tell me what is wrong?
I am REALLY bad in regular expressions..
Thank you so much..
I assume you want to replace it with a string consisting of asterisks of the same length, is that right? Like this:
$len = strlen($badword);
$var = preg_replace("/\b$badword\b/", str_repeat('*',$len), $var);