php怎么替换指定位置的字符串
时间:2021-03-23
来源:互联网
今天PHP爱好者给大家带来可以使用str_replace()函数来替换指定位置的字符串,语法格式“substr_replace(string,replacement,start,length)”,参数start用于指定替换位置(在字符串的何处开始替换)。快来看看吧。
本教程操作环境:windows7系统、PHP7.1版,DELL G3电脑
php替换指定位置字符串
<?php
$str = 'hello world';
// 替换指定位置的字符
$str = substr_replace($str,"earth",6);;
// 显示字符
echo $str;
?>
输出:
hello earth
相关函数说明:
substr_replace() 函数把字符串的一部分替换为另一个字符串。语法如下:
substr_replace(string,replacement,start,length)
string | 必需。规定要检查的字符串。 |
replacement | 必需。规定要插入的字符串。 |
start | 必需。规定在字符串的何处开始替换。
|
length | 可选。规定要替换多少个字符。默认是与字符串长度相同。
|
注释:如果 start 参数是负数且 length 小于或者等于 start,则 length 为 0。
以上就是php怎么替换指定位置的字符串的详细内容,更多请关注php爱好者其它相关文章!
-
Android SurFaceView的用法详解 时间:2025-05-01
-
Win10共享打印机709错误的原因及解决方法 时间:2025-05-01
-
什么是binkw32.dll binkw32.dll丢失的解决方法 时间:2025-05-01
-
Python中split函数详解(参数说明、作用、用法) 时间:2025-05-01
-
面向对象设计原则有哪些?每个原则是如何定义的? 时间:2025-05-01
-
C++中取整函数(ceil、floor、round)详解(定义、用法、示例) 时间:2025-05-01
今日更新
-
引线标注怎么设置
阅读:23
-
c语言源程序文件名的后缀是什么
阅读:32
-
thinkphp5怎么增加允许指定ip访问模块配置
阅读:24
-
word的工具栏不见了怎么办
阅读:20
-
composer配置中国镜像(解决没有VPN)
阅读:25
-
php怎么关闭xdebug
阅读:26
-
excel怎么同时选中不相邻的两列
阅读:20
-
远程守护是什么功能
阅读:21
-
汇总PHP常见数组函数与实例【基础】
阅读:23
-
linux怎么关闭php服务
阅读:23