: This article mainly introduces the php string replacement function. if you are interested in the PHP Tutorial, refer to it. In php, there are several character replacement functions, such as str_replace, substr_replace, preg_replace, preg_split, and str_split:
1, Str_replace () function:
Use one string to replace other characters in the string. (Case sensitive, binary secure)
(1) format: str_replace (find, replace, string, count)
(2) parameter description:
Find is required. Specifies the value to be searched.
Replace is required. Specifies the value to replace the value in find.
String is required. Specifies the string to be searched.
Count is optional. A variable that counts the number of replicas
Supplement: If count is specified, its value is set to the number of times it is replaced.
2, str_ireplace () function:
Use one string to replace other characters in the string. (Case insensitive, binary secure)
(1) format: str_ireplace (find, replace, string, count)
(2) parameters are the same as above
3. substr_replace () function:
Replace one part of the string with another. (1)
(1) format: substr_replace (string, replacement, start, length)
(2) parameter description
String is required. Specifies the string to be checked.
Replacement is required. Specifies the string to be inserted.
Start is required. Specifies where the string starts replacement.
Positive number-start replacement at the start offset
Negative number-replace with the start offset at the end of the string
0-START replacement at the first character in the string
Charlist is 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
Note: If start is a negative number and the length is less than or equal to start, the length is 0.
4, preg_replace (pattern, replacement, subject, limit =-1, $ count)
(1) function: Search and replace a regular expression
(2) parameter description
Pattern is required. The mode to be searched.
Replacement is required. String or array to be replaced.
Subject is required. String or array to be replaced.
The number of limit replacements. -1 is infinite
Count: The number of times the replacement is completed, the variable
5, preg_split (pattern, subject, limit =-1, flag)
(1) function: use a regular expression to split a string
(2) parameter description
Pattern is required. The mode to be searched.
Lacement is required. String or array to be replaced.
Subject is required. String to be replaced.
The limit string can be separated by up to limit.
Flag mode
6, str_split (subject, length)
(1) function: split strings into arrays
(2) parameter description
Subject string.
The length of each segment.
The above describes the php string replacement function, including some content, and hope to be helpful to friends who are interested in the PHP Tutorial.