1

Hello im trying to filter swear words from comments when i display these comments from database

this my code :

<?php
function filterwords($text){
$filterWords = array('hekk','darn','fut');
$filterCount = sizeof($filterWords);
for($i=0; $i<$filterCount; $i++){
$text = preg_replace('/\b'.$filterWords[$i].'\b/ie',"str_repeat('*',strlen('$0'))",$text);

}
return $text;
}

echo filterwords($pcom['description']);
?>

i was expecting for exmaple i will replace a text like this "what the hekk" into "what the ****" but its shows "Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback" i dont know how to use preg_replace_callback how can work with it (modify the code using replace_callback) or is there any other method i can use to filter swear words from a text

  • Required reading: https://blog.codinghorror.com/obscenity-filters-bad-idea-or-incredibly-intercoursing-bad-idea/ and https://en.wikipedia.org/wiki/Scunthorpe_problem – ceejayoz Apr 25 '19 at 15:27

0 Answers0