Created
January 21, 2016 22:43
-
-
Save kjbrum/298d8a898df8f1c9230b to your computer and use it in GitHub Desktop.
Replace the last occurrence of a string.
This file contains hidden or 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
<?php | |
/** | |
* Replace the last occurrence of a string. | |
* | |
* @param string $search The string to search for | |
* @param string $replace The string to replace the search string | |
* @param string $subject The string to search and replace | |
* @return string The new string | |
*/ | |
function str_replace_last( $search=null, $replace=null, $subject=null ) { | |
return strrev( implode( strrev( $replace ), explode( $search, strrev( $subject ), 2 ) ) ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment