close
[php]str_ireplace() 函數使用一個字符串替換字符串中的另一些字符。
註釋:該函數對大小寫不敏感。請使用 str_replace() 執行對大小寫敏感的搜索。
例子 1
<?php
echo str_ireplace("world","John","Hello world!");
?>
輸出:
Hello John!
例子 2
在本例中,我們將演示帶有數組和 count 變量的 str_ireplace() 函數:
<?php
$arr = array("blue","red","green","yellow");
print_r(str_ireplace("red","pink",$arr,$i));
echo "Replacements: $i";
?>
輸出:
Array
(
[0] => blue
[1] => pink
[2] => green
[3] => yellow
)
Replacements: 1
例子 3
<?php
$find = array("Hello","world");
$replace = array("B");
$arr = array("Hello","world","!");
print_r(str_ireplace($find,$replace,$arr));
?>
輸出:
Array
(
[0] => B
[1] =>
[2] => !
)
全站熱搜