You are at right place then. check out the function below which easily replaces the last occurrence of sub string from supplied string.
- function str_lreplace(mixed $search, mixed $replace, mixed $subject)
- {
- return substr_replace($subject, $replace, strrpos($subject, $search), strlen($search));
- }
