Copy the 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.
Syntax
substr_replace(string,replacement,start,length)
Parameters | Description |
---|---|
string | Required. Specifies the string to check. |
replacement | Required. Specifies the string to be inserted. |
start |
Required. Specifies where in the string to begin replacement.
|
charlist |
Optional. Specifies how many characters to 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);
?>
The above introduces the irreplacable substr_replace of PHP to replace the characters between the specified two positions with numbers, including the irreplacable content. I hope it will be helpful to friends who are interested in PHP tutorials.