Code to replace the last occurrence of a string in a string using PHP
output :
<?php function str_lreplace($search, $replace, $subject) { $pos = strrpos($subject, $search); print $pos; if($pos !== false) { $subject = substr_replace($subject, $replace, $pos, strlen($search)); } echo $subject; return $subject; } str_lreplace('hello','world','this is hello world for checking hello when hello'); ?>
output :

Comments
Post a Comment