PHP 新手教學 String | str_ireplace的使用說明

Table of Contents

Table of Contents

str_ireplace

與搜尋目標不分大小寫外,其他與str_replace相同。 將$subject中的$search部分用$replace代換,並返回代換後的結果。$subject可為字串或是字串陣列。

str_ireplace ( mixed $search , mixed $replace , mixed $subject [, int &$count ] ) : mixed

search 搜尋目標,可以為一組陣列。

replace 置換內容,可以為一組陣列。

Example:

$test1 = "This is %user_name.";
print_r(str_ireplace("%user_name", "CyuBlog", $test1));

$test2 = array(
    "Hi, this is %name",
    "%name is a web blog"
    );
print_r(str_ireplace("%Name", "CyuBlog", $test2));


$test3 = array(
    "ABc",
    "abc",
    "Abc"
    );
print_r(str_ireplace(array("a", "b", "c"), array("1" , "2", "3"), $test3));

Output:

// str_replace($test1):
This is CyuBlog.

// str_replace($test2):
Array
(
    [0] => Hi, this is CyuBlog
    [1] => CyuBlog is a web blog
)

// str_replace($test3):
Array
(
    [0] => 123
    [1] => 123
    [2] => 123
)

相關函數