I have a string and I want to replace the last 7 charators of the string with "#". For example I have "MerryChristmasu87yujh7" I want to replace "87yujh7" with seven "#######". So, the final string will be "MerryChristmasu#######".
I have tried the follow code but it returns "MerryChristmasu#######1". It does not convert all seven ending characters.
$string = "MerryChristmasu87yujh7";
$match = substr($string, -7, -1);
$result = str_replace($match, "#######", $string);
See Question&Answers more detail:os