文字列があり、文字列の最後の 7 文字を "#" に置き換えたいと考えています。たとえば、"MerryChristmasu87yujh7" があり、"87yujh7" を 7 つの "#######" に置き換えたいとします。したがって、最後の文字列は「MerryChristmasu#######」になります。
次のコードを試してみましたが、「MerryChristmasu#######1」が返されます。7 つの末尾文字すべてが変換されるわけではありません。
$string = "MerryChristmasu87yujh7";
$match = substr($string, -7, -1);
$result = str_replace($match, "#######", $string);