Copy CodeThe 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)
Parameters |
Description |
String |
Necessary. Specifies the string to check. |
Replacement |
Necessary. Specifies the string to insert. |
Start |
Necessary. Specifies where the string begins to be replaced.
- Positive number-starts with the first offset
- Negative number-replaces the start offset starting at the end of a string
- 0-Start the substitution at the first character in the string
|
Charlist |
Optional. Specifies the number of characters to replace.
- Positive number-The length of the string being replaced
- Negative-the number of characters to be replaced starting at the end of the string
- 0-Insert rather than replace
|
Hints and Notes
Note: If start is negative and length is less than or equal to start, length is 0.
Example
Copy the Code code as follows:
Echo substr_replace ("Hello World", "Earth", 6);
?>
Output:
Hello Earth
The above describes the irreplacable PHP substr_replace will specify the characters between the two positions to replace the number, including the irreplacable aspect of the content, I hope to be interested in PHP tutorial friends helpful.