如何分解忽略分隔符大小写的字符串


How to explode a string ignoring the case of the delimiter?

我有以下代码:

$string = "zero Or one OR two or three";
print_r(explode("or", $string));

现在,这会导致:

Array ( [0] => zero Or one OR two [1] => three ) 

但是我想忽略分隔符的大小写,以便它适用于OrOR、...我的结果是:

Array ( [0] => zero [1] => one [2] => two [3] => three ) 

我该怎么做?

使用 preg_split()

$string = "zero Or one OR two or three";
$keywords = preg_split("/or/i", $string);
echo '<pre>';print_r($keywords);echo '</pre>';

输出:

Array
(
    [0] => zero 
    [1] =>  one 
    [2] =>  two 
    [3] =>  three
)