Created
June 16, 2013 16:56
-
-
Save xafarali/5792644 to your computer and use it in GitHub Desktop.
String Relace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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