php中字符串與字符替換用str_replace()函數(shù)。str_replace()函數(shù)替換字符串中的一些字符(區(qū)分大小寫(xiě)),函數(shù)語(yǔ)法為:【str_replace(find,replace,string,count)】。
str_replace() 函數(shù)替換字符串中的一些字符(區(qū)分大小寫(xiě))。
(推薦教程:php圖文教程)
函數(shù)語(yǔ)法:
str_replace(find,replace,string,count)
(視頻教程推薦:php視頻教程)
參數(shù)說(shuō)明:
-
find 必需。規(guī)定要查找的值。
-
replace 必需。規(guī)定替換 find 中的值的值。
-
string 必需。規(guī)定被搜索的字符串。
-
count 可選。一個(gè)變量,對(duì)替換數(shù)進(jìn)行計(jì)數(shù)。
代碼舉例:
<?php $arr = array("blue","red","green","yellow"); print_r(str_replace("red","pink",$arr,$i)); echo "Replacements: $i"; ?>