当前位置: 首页 > 网络学院 > 服务端脚本教程 > PHP > substr_replace() 函数
The substr_replace() function replaces a part of a string with another string.
substr_replace()函数的作用是:替换字符串中一部分为另一字符串。
substr_replace(string,replacement,start,length) |
| Parameter参数 | Description描述 |
|---|---|
| string | Required. Specifies the string to check 必要参数。指定字符串对象 |
| replacement | Required. Specifies the string to insert 必要参数。指定插入的字符串 |
| start | Required. Specifies where to start replacing in the string 必要参数。指定开始返回字符串的位置
|
| length | Optional. Specifies how many characters should be replaced. Default is the same length as the string. 可选参数。指定返回的字符串长度。默认值是整个字符串
|
Note: If start is a negative number and length is less than or equal to start, length becomes 0.
注意:如果上述的start参数设置为负数,而length参数数值小于或等于start数值,那么length的值自动为0。
<?php
echo substr_replace("Hello world","earth",6);
?> |
The output of the code above will be:
上述代码将输出下面的结果:
Hello earth |
评论 (0) All