把字符串 "Hello world!" 中的字符 "WORLD"(不區(qū)分大小寫)替換成 "Shanghai":
<?php echo str_ireplace("WORLD","Shanghai","Hello world!"); ?>
str_ireplace() 函數(shù)替換字符串中的一些字符(不區(qū)分大小寫)。
該函數(shù)必須遵循下列規(guī)則:
注釋:該函數(shù)不區(qū)分大小寫。請使用 str_replace() 函數(shù)來執(zhí)行區(qū)分大小寫的搜索。
注釋:該函數(shù)是二進制安全的。
str_ireplace(find,replace,string,count)
參數(shù) | 描述 |
---|---|
find | 必需。規(guī)定要查找的值。 |
replace | 必需。規(guī)定替換 find 中的值的值。 |
string | 必需。規(guī)定被搜索的字符串。 |
count | 可選。一個變量,對替換數(shù)進行計數(shù)。 |
返回值: | 返回帶有替換值的字符串或數(shù)組。 |
PHP 版本: | 5+ |
更新日志: | 在 PHP 5.0 中,新增了 count 參數(shù)。 |
使用帶有數(shù)組和 count 變量的 str_ireplace() 函數(shù):
<?php
$arr = array("blue","red","green","yellow");
print_r(str_ireplace("RED","pink",$arr,$i)); // 此函數(shù)對大小寫不敏感
echo "替換數(shù):$i";
?>
使用帶有需要替換的元素少于查找到的元素的 str_ireplace() 函數(shù):
<?php $find = array("HELLO","WORLD"); $replace = array("B"); $arr = array("Hello","world","!"); print_r(str_ireplace($find,$replace,$arr)); ?>
如對本文有疑問,請?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會為你解答??! 點擊進入論壇
Powered by 365建站網(wǎng) RSS地圖 HTML地圖
copyright © 2013-2024 版權(quán)所有 鄂ICP備17013400號