Skip to content

Instantly share code, notes, and snippets.

@xafarali
Created June 16, 2013 16:56
Show Gist options
  • Save xafarali/5792644 to your computer and use it in GitHub Desktop.
Save xafarali/5792644 to your computer and use it in GitHub Desktop.
String Relace
function str_lreplace($needle, $replace, $haystack)
{
/*
int strrpos ( string $haystack , string $needle [, int $offset = 0 ] )
Find the numeric position of the last occurrence of needle in the haystack string.
*/
$pos = strrpos($haystack, $needle);
if($pos !== false)
{
$subject = substr_replace($haystack, $replace, $pos, strlen($needle));
}
return $subject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment