Home > Article > Backend Development > What function is used to replace strings and characters in php
Str_replace() function is used to replace strings and characters in php. The str_replace() function replaces some characters in a string (case-sensitive). The function syntax is: [str_replace(find,replace,string,count)].
str_replace() function replaces some characters in a string (case sensitive).
(Recommended tutorial: php graphic tutorial)
Function syntax:
str_replace(find,replace,string,count)
(Recommended video tutorial: php video Tutorial)
Parameter description:
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.
Code example:
<?php $arr = array("blue","red","green","yellow"); print_r(str_replace("red","pink",$arr,$i)); echo "Replacements: $i"; ?>
The above is the detailed content of What function is used to replace strings and characters in php. For more information, please follow other related articles on the PHP Chinese website!