Forum Moderators: coopster
$string = $desc_jj;
$replaceme = ' ';
$replacewith = ' ' . $desc_kw_array_kw[array_rand($desc_kw_array_kw)] . ' ';
$nthtimes = 2;
$desc_jj = preg_replace("/((.*?)(".$replaceme.")){".$nthtimes."}/e", '(preg_replace("/".$replaceme."$/", "", "\0")).$replacewith', $string);
function random_replace() {
$replacements = array('lorem', 'ipsum', 'dolor', 'sit', 'amet');
return rand(0,1) ? ' '. $replacements[rand(0, 4)]. ' ' : ' ';
}
$string = 'The quick brown fox jumped over the lazy dog.';
$pattern = '/\s/';
$results = preg_replace_callback($pattern, 'random_replace', $string);
print_r($results);