Home > Article > Backend Development > How to replace all specified characters in Php
Php method to replace all specified characters: 1. Use the "str_replace(find,replace,string,count)" method to replace; 2. Use the "preg_replace()" method to replace.
The operating environment of this article: Windows 7 system, PHP version 7.1, Dell G3 computer.
How to replace all specified characters in Php?
Commonly used functions are:
str_replace() and preg_replace().
str_replace() function uses a string to replace other characters in a string.
str_replace(find,replace,string,count)
Parameters
find Required. Specifies the value to look for.
replace Required. Specifies the value to replace the value in find.
string Required. Specifies the string to be searched for.
count Optional. A variable counting the number of substitutions.
str_replace("raykaeso", "leixuesong", "raykaeso love php");
preg_replace ( pattern , replacement , subject,limit = -1 ,$count )
Function: Perform a regular expression search and replace
pattern required. The pattern to search for.
replacement Required. String or array to use for replacement.
subject Required. String or array to be replaced.
limit the number of replacements. -1 is unlimited
count number of times to complete the substitution, variable
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to replace all specified characters in Php. For more information, please follow other related articles on the PHP Chinese website!