3 回答
已采納

慕田峪1134683
TA貢獻(xiàn)12條經(jīng)驗(yàn) 獲得超3個(gè)贊
str_repalce($a,$b,$con);$a,$b可以是數(shù)組的形式來(lái)進(jìn)行替換.

錯(cuò)過(guò)了年華
TA貢獻(xiàn)56條經(jīng)驗(yàn) 獲得超22個(gè)贊
str_replace()函數(shù):對(duì)字符進(jìn)行替換操作
聲明:mixed str_replace(mixed $search, mixed $replace, mixed $subject [,int &$count])
$search表示查找的目標(biāo)值,$replace參數(shù)表示$search的替換值,$subject參數(shù)表示需要被操作的字符串,
$count參數(shù)是用來(lái)統(tǒng)計(jì)$search參數(shù)被替換的次數(shù),是一個(gè)可選參數(shù),與其他參數(shù)不同的是,在完成str_replace()函數(shù)的調(diào)用后,該參數(shù)還可以在函數(shù)外部直接被調(diào)用。
例子:
$str1="i like play football, and he is also like play football";
$str2="basketball";
echo "替換前字符串為:".$str1."<br>";
$str=str_replace("football",$str2,$str1,$count);
echo "替換后字符串為:".$str."<br>";
echo "字符串中football被替換的次數(shù)為:".$count."<br>";
- 3 回答
- 0 關(guān)注
- 1422 瀏覽
添加回答
舉報(bào)
0/150
提交
取消