英 [r??ple?s]? ?美 [r??ples]
vt.代替;替換;把…放回原位;(用…)替換
第三人稱單數(shù): replaces 現(xiàn)在分詞: replacing 過(guò)去式: replaced 過(guò)去分詞: replaced
php str_replace()函數(shù) 語(yǔ)法
作用:字符串替換操作,區(qū)分大小寫(xiě)
語(yǔ)法:str_replace(find,replace,string,count)
參數(shù):
參數(shù) | 描述 |
find? ?? | 必需。規(guī)定要查找的值。 |
replace? ?? | 必需。規(guī)定替換?find?中的值的值。? |
string? ?? | 必需。規(guī)定被搜索的字符串。 |
count? ?? | 可選。對(duì)替換數(shù)進(jìn)行計(jì)數(shù)的變量。? ?? |
說(shuō)明:以其他字符替換字符串中的一些字符(區(qū)分大小寫(xiě))。如果搜索的字符串是數(shù)組,那么它將返回?cái)?shù)組。如果搜索的字符串是數(shù)組,那么它將對(duì)數(shù)組中的每個(gè)元素進(jìn)行查找和替換。如果同時(shí)需要對(duì)數(shù)組進(jìn)行查找和替換,并且需要執(zhí)行替換的元素少于查找到的元素的數(shù)量,那么多余元素將用空字符串進(jìn)行替換。如果查找的是數(shù)組,而替換的是字符串,那么替代字符串將對(duì)所有查找到的值起作用。
php str_replace()函數(shù) 示例
<?php echo str_replace("world","php.cn","Hello world!"); ?>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
輸出:
Hello php.cn!
<?php $i = "i like JavaScript"; echo str_replace("JavaScript","php",$i); ?>
運(yùn)行實(shí)例 ?
點(diǎn)擊 "運(yùn)行實(shí)例" 按鈕查看在線實(shí)例
輸出:
i like php