I need to find all occurrences of a array of strings (original $list has over 780 items) in a sentence, and replace everything except the first letter with html dashes.
This is my current code:
function sanitize($string) {
$list = array(
"dumb",
"stupid",
"brainless"
);
# replace bad words
$string = str_replace($list, '–', $string);
return $string;
}
echo sanitize('hello, i think you are not intelligent, you are actually dumb and stupid.');
This is the current result:
hello, i think you are not intelligent, you are actually – and –</p>
The result should be:
hello, i think you are not intelligent, you are actually d––– and s–––––</p>
Any ideas on how to approach this? Thanks!