Home > Article > Backend Development > What is the character replacement function in php
The character replacement function in php is str_replace(). The str_replace() function is used to replace some characters in a string. This function is case-sensitive. Function syntax: [str_replace(find,replace,string,count)].
#The character replacement function in php is str_replace().
(Recommended tutorial: php tutorial)
Function introduction:
str_replace() function replaces some characters in the string (case sensitive) .
Note: This function is case-sensitive.
Function syntax:
str_replace(find,replace,string,count)
Parameter introduction:
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 implementation:
<?php //实例一:字符串替换字符串 $str1 = str_replace("red","black","red green yellow pink purple"); echo $str1.""; //输出结果为black green yellow pink purple ?> <?php //实例二:字符串替换数组键值 $arr = array("blue","red","green","yellow"); $str1 = str_replace("red","pink",$arr,$i); print_r($str1); ?>
The above is the detailed content of What is the character replacement function in php. For more information, please follow other related articles on the PHP Chinese website!