Replace character's position in a string

后端 未结 4 855
小蘑菇
小蘑菇 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:23

    For replacing, use function

    $str    = 'bar';
    $str[1] = 'A';
    echo $str; // prints bAr
    

    or you could use the library function substr_replace as:

    $str = substr_replace($str,$char,$pos,1);
    

    similarly for 3rd position

提交回复
热议问题