- microtime: documentation ( source)
- substr_replace: documentation ( source)
- stripos: documentation ( source)
<?php
$start = microtime(true);
$string = 'JavaSCRIPT and pHp are testing test-ground for TEST !';
$censor = ['php' => 2,'javascript' => 2,'test' => 3];
foreach ($censor as $word => $position) {
while (($pos = stripos($string, $word)) !== false) {
$string = substr_replace($string, '*', $pos + $position - 1, 1);
}
}
echo $string;
$end = (microtime(true));
echo '<br />';
echo $end - $start;