How to replace some characters in a custom string in the php tutorial
The substr_replace () function replaces some characters in the custom string.
Syntax: substr_replace (str, repl, start, [int length])
Syntax description:
Str -- required parameter, which specifies the original string to be operated
Repl -- specify the new string after replacement
Start -- specify the start position of the string to be replaced
Length -- optional parameter, which specifies the length of the returned string.
Use the substr_replace () function to replace a string:
Instance code:
$ B = "Manual ";
$ C = "zero's php blog ";
Echo substr_replace ($ c, $ B, 9, 4 );
?>
Output result:
Zero php Manual
| Parameters |
Description |
| String |
Required. Specifies the string to be checked. |
| Replacement |
Required. Specifies the string to be inserted. |
| Start |
Required. Specifies where the string starts replacement.
- Positive number-inStartOffset start to replace
- Negative number-the number at the end of the stringStartOffset start to replace
- 0-start replacement at the first character in the string
|
| Charlist |
Optional. Specifies the number of characters to replace.
- Positive number-length of the string to be replaced
- Negative number-Number of replaced characters starting from the end of the string
- 0-insert instead of replace
|