replace last occurrence of substring from string in php

Are you looking out for a built in function in php which replace last occurrence of sub string from string??

You are at right place then. check out the function below which easily replaces the last occurrence of sub string from supplied string.

  1. function str_lreplace(mixed $search, mixed $replace, mixed $subject)
  2. {
  3. return substr_replace($subject, $replace, strrpos($subject, $search), strlen($search));
  4. }


Roger Rutishauser said...


Post a Comment

Share this post with your friends