RsD0p9BK
1/27/2015 - 9:44 AM

last_occurence.php

// заменить последнее вхождение
$string = 'The quick brown fox, fox, fox jumps over the lazy fox!!!';
echo preg_replace('/(fox(?!.*fox.*))/', 'dog', $string);

// PHP Replace Last Occurence of a String in a String?
// http://stackoverflow.com/questions/3835636/php-replace-last-occurence-of-a-string-in-a-string