阅读量:0
在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 )
在这两个示例中,我们使用了逗号、竖线以及它们的组合作为分隔符。你可以根据需要自定义分隔符数组。