I am trying build a function that can uniformly change words.e. The black cat is sitting on the mat. I want every two words(or nth words) to end up like The MOD cat MOD sitting MOD the MOD. The words are changed uniformly. Currently I have:
$alltext = 'The black cat is sitting on the mat';
//using regex break text into words into an array $pattern = '/([a-zA-Z]|\xC3[\x80-\x96\x98-\xB6\xB8-\xBF]|\xC5[\x92\x93\xA0\xA1\xB8\xBD\xBE]){1,}/'; $n_words = preg_match_all($pattern, $input_str, $match_arr, PREG_OFFSET_CAPTURE); $wordcnt = 0;
foreach ($match_arr[0] as $val) { $wordcnt++; $aword = $val[0];
$wordpos = $val[1];
$alltext = str_ireplace($wordpos, $aword, 'MOD'.changer($aword),$alltext);
}
function changer($in)
{
$in = $in.'IFY';
return $in;
}
This does not replace nth words uniformly. How can do this?