// заменить последнее вхождение
$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