Replace character's position in a string

后端 未结 4 863
小蘑菇
小蘑菇 2020-12-21 12:37

In PHP, how can you replace the second and third character of a string with an X so string would become sXXing?

The string\'s

4条回答
  •  佛祖请我去吃肉
    2020-12-21 13:38

    function mb_substr_replace($string, $replacement, $start, $length=0)
    {
        return mb_substr($string, 0, $start) . $replacement . mb_substr($string, $start+$length);
    }
    

    same as above, but standardized to be more like substr_replace (-substr- functions usually take length, not end position)

提交回复
热议问题