Is it possible to tell which string or strings are replaced when using PHP's str_replace
function?
In other words, I have a call similar to the following
$subject = str_replace($search, $replace, $subject, $count);
Where $search
and $replace
are both arrays. If $count > 0
I want to figure out which strings were replaced and do something with them. Is something like this possible? Is there a function which does it? Should I just rewrite my code?
A possible approach is array_diff()
$str = array('something to rplace', 'anything else', 'sth else', 'one more');
$str2 = $str;
$str = str_replace($search, $replace, $str, $count);
var_dump( array_diff($str2, $str) );