php怎么替换字符串的第三位字符
- 建站笔记
- 2022-05-11
- 650
在php中,可以使用substr_replace()函数来替换指定字符串的第三位字符,该函数可以从字符串指定位置开始,替换指定长度的字符;语法为“substr_replace(字符串, "替换值", 2,1)”。
本教程操作环境:windows7系统、PHP7.1版、DELL G3电脑
在php中,可以使用substr_replace()函数来替换指定字符串的第三位字符。
示例:
<?php $str = '12345678'; $replace = 'h'; echo substr_replace($str, $replace, 2,1); ?>
说明:
substr_replace() 函数把字符串的一部分替换为另一个字符串。
substr_replace() 函数可以从字符串指定位置开始,替换指定长度的字符。
语法:
substr_replace(string,replacement,start,length)
返回值: 返回被替换的字符串。如果 string 是一个数组,则返回数组。
本文由白琉璃于2022-05-11发表在白琉璃源码网,如有侵权或疑问,请联系我们,谢谢。
本文链接:https://www.bailiuli.com/t/2874.html
发表评论