PHP substr_replace replaces the character between the specified two locations with the * code. For more information, see.
The code is as follows:
$ Username = "zongzi ";
Echo substr_replace ($ username, '**', '1', '2 ');
Definition and usage
The substr_replace () function replaces one part of the string with another.
Syntax
substr_replace(string,replacement,start,length)
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
|
Tips and comments
Note: IfStartIs negative andLengthLess than or equalStart, ThenLength0.
Example
The code is as follows:
Echo substr_replace ("Hello world", "earth", 6 );
?>
Output:
Hello earth