In PHP, you can use the "substr_replace" function to replace a string from a specified position. The syntax is "substr_replace(string,replacement,start,length)". The parameter start means to start replacing from the specified position.
Recommended: "PHP Video Tutorial"
php method to replace characters starting from the specified position
Definition and usage
The substr_replace() function replaces part of a string with another string.
Syntax
substr_replace(string,replacement,start,length) echo substr_replace("hello world","earth",6);
Parameters
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.
Positive numbers - replace at the start offset
Negative numbers - replace at the start offset from the end of the string
0 - replace at the character Start replacing
charlist
from the first character in the string. 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 from the end of the string
0 - insert instead of replace
The above is the detailed content of How to replace string from specified position in php. For more information, please follow other related articles on the PHP Chinese website!