<?php
function censorWords($string) {
$badwords = ['devbest', 'rastalulz', 'melody'];
foreach ($badwords as $badword) {
$string = preg_replace('/' . $badword . '/gi', '****', $string);
}
return $string;
}
echo censorWords('RastaLulz and Melody met on DevBest and he found out she was under-aged.');
//=> **** and **** met on **** and he found out she was under-aged.
?>