0

I have this basic profanity filter code;

$body = "This is a naughty word";   
$filterWords = array('naughty', 'word');
$filterCount = sizeof($filterWords);

for($i=0; $i<$filterCount; $i++){
    $body = preg_replace('/\b'.$filterWords[$i].'\b/ie',"str_repeat('*',strlen('$0'))",$body);
    }

echo $body;

However it's not working, just outputs nothing. It used to work fine. Any idea where the error is?

user1022585
  • 13,061
  • 21
  • 55
  • 75
  • Revamp to `preg_replace_callback` as described in https://stackoverflow.com/a/15454454/3832970 – Wiktor Stribiżew Jul 12 '18 at 08:29
  • 3
    Apparently, the `/e` modifier is deprecated since forever: https://3v4l.org/PBv8Z – Loek Jul 12 '18 at 08:29
  • 1
    Ah profanity filters, the bane of [Scunthorpe](https://en.wikipedia.org/wiki/Scunthorpe_problem)... – CD001 Jul 12 '18 at 08:33
  • @Loek "Forever" in this case is "[since PHP 5.5](http://php.net/manual/en/reference.pcre.pattern.modifiers.php)", which is just over 5 years. It's just that 3v4l only checks supported versions by default, and 5.5 reached EOL 2 years ago. – IMSoP Jul 12 '18 at 08:33
  • 5 years in software development that is not C or C++ pretty much is "forever" as far as I'm concerned. But fair enough, thanks for pointing it out! – Loek Jul 12 '18 at 08:36

0 Answers0