在PHP中,explode() 函數用于將字符串分割為數組
$string = "one,two|three-four";
$delimiter = "/[,|-|]";
$array = explode($delimiter, $string);
print_r($array);
輸出結果:
Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)
$string = "one,two|three-four";
$delimiters = array(",", "|");
$array = explode($delimiters, $string);
print_r($array);
輸出結果:
Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)
在這兩個示例中,我們使用了逗號、豎線以及它們的組合作為分隔符。你可以根據需要自定義分隔符數組。