php中字符替換函數(shù)是str_replace()。str_replace()函數(shù)用于替換字符串中的一些字符,該函數(shù)是區(qū)分大小寫的。函數(shù)語法:【str_replace(find,replace,string,count)】。
php中字符替換函數(shù)是str_replace()。
(推薦教程:php教程)
函數(shù)介紹:
str_replace() 函數(shù)替換字符串中的一些字符(區(qū)分大小寫)。
注意:該函數(shù)是區(qū)分大小寫的。
函數(shù)語法:
str_replace(find,replace,string,count)
參數(shù)介紹:
-
find 必需。規(guī)定要查找的值。
-
replace 必需。規(guī)定替換 find 中的值的值。
-
string 必需。規(guī)定被搜索的字符串。
-
count 可選。一個變量,對替換數(shù)進(jìn)行計數(shù)。
代碼實(shí)現(xiàn):
<?php //實(shí)例一:字符串替換字符串 $str1 = str_replace("red","black","red green yellow pink purple"); echo $str1.""; //輸出結(jié)果為black green yellow pink purple ?> <?php //實(shí)例二:字符串替換數(shù)組鍵值 $arr = array("blue","red","green","yellow"); $str1 = str_replace("red","pink",$arr,$i); print_r($str1); ?>