The functions used to replace strings in PHP are as follows: 1. str_replace(), used to replace matching items in the string; 2. str_ireplace(), similar to str_replace(), but different Upper and lower case; 3. preg_replace(), uses regular expressions for string replacement.
Function to replace string in PHP
Question: Used to replace string in PHP What are the string functions?
Answer: The following functions are provided in PHP for replacing strings:
1. str_replace()
str_replace()
Function is used to replace one or more matches in a string.
Syntax:
<code class="php">str_replace(string needle, string replace, string subject)</code>
Parameters:
needle
- The string to find and replace replace
- the string to replace needle
subject
- the string to replace ## 2. str_ireplace()
str_ireplace() function is similar to
str_replace(), except that it is case-sensitive.
<code class="php">str_ireplace(string needle, string replace, string subject)</code>
- The string to find and replace
- the string to replace
needle
- the string to replace
preg_replace()
function uses regular expressions to replace strings. Syntax:
<code class="php">preg_replace(string pattern, string replacement, string subject)</code>
Parameters:
The above is the detailed content of function to replace string in php. For more information, please follow other related articles on the PHP Chinese website!