Copy code The code is as follows:
$username = "zongzi";
echo substr_replace($username,'**', '1','2');
Definition and usage
The substr_replace() function replaces part of a string with another string.
Grammar
substr_replace(string,replacement,start,length)
Copy after login
Parameters |
Description |
string |
Required. Specifies the string to check. |
replacement |
Required. Specifies the string to be inserted. |
start |
参数 |
描述 |
string |
必需。规定要检查的字符串。 |
replacement |
必需。规定要插入的字符串。 |
start |
必需。规定在字符串的何处开始替换。
- 正数 - 在第 start 个偏移量开始替换
- 负数 - 在从字符串结尾的第 start 个偏移量开始替换
- 0 - 在字符串中的第一个字符处开始替换
|
charlist |
可选。规定要替换多少个字符。
- 正数 - 被替换的字符串长度
- 负数 - 从字符串末端开始的被替换字符数
- 0 - 插入而非替换
|
Required. Specifies where in the string to begin replacement.
- Positive number - start replacement at offset
start
- Negative numbers - start replacing at start
offset from the end of the string
- 0 - Start replacement at the first character in the string
|
charlist |
Optional. Specifies how many characters to replace.
- Positive number - the length of the string to be replaced
- Negative number - the number of characters to be replaced starting from the end of the string
- 0 - insert instead of replace
|
Tips and Notes
Note:
If start
is negative and
length
is less than or equal to start, then length is 0.
Example
Copy code
The code is as follows:
echo substr_replace("Hello world" ,"earth",6); ?>
Output: Hello earth
http://www.bkjia.com/PHPjc/323206.htmlwww.bkjia.comtrue
http: //www.bkjia.com/PHPjc/323206.html
Copy the code as follows: $username = "zongzi"; echo substr_replace($username,'**',' 1','2'); Definition and usage substr_replace() function replaces part of a string with another string...