php中字符替換函數是str_replace()。str_replace()函數用于替換字符串中的一些字符,該函數是區(qū)分大小寫的。函數語法:【str_replace(find,replace,string,count)】。
php中字符替換函數是str_replace()。
(推薦教程:php教程)
函數介紹:
str_replace() 函數替換字符串中的一些字符(區(qū)分大小寫)。
注意:該函數是區(qū)分大小寫的。
函數語法:
str_replace(find,replace,string,count)
參數介紹:
-
find 必需。規(guī)定要查找的值。
-
replace 必需。規(guī)定替換 find 中的值的值。
-
string 必需。規(guī)定被搜索的字符串。
-
count 可選。一個變量,對替換數進行計數。
代碼實現:
<?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); ?>