定義和用法
str_ireplace() 函式使用一個字元串替換字元串中的另一些字元。
語法
| str_ireplace(find,replace,string,count) |
| 參數 | 描述 |
| find | 必需。規定要查找的值。 |
| replace | 必需。規定替換 find 中的值的值。 |
| string | 必需。規定被搜尋的字元串。 |
| count | 可選。一個變數,對替換數進行計數。 |
提示和注釋
注釋:該函式對大小寫不敏感。請使用 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] => ! ) |
PHP String 函式
