$date could be "23/09/2012" or "23-09-2012" or "23\09\2012"
preg_split('/[\/\-\\]/', $date);
不确定为什么PHP会继续抛出missing terminating ] error
?
答案 0 :(得分:11)
preg_split('/[\/\-\\]/', $date);
^escaping the closing ']'
请执行以下操作,以消除歧义
preg_split('/[\/\-\\\\]/', $date);
无需转义-
,但您也可以使用\-
。
代码:
$date = 'as\sad-s/p';
$slices = preg_split('/[\/\-\\\\]/', $date);
print_r($slices);
输出:
Array ( [0] => as [1] => sad [2] => s [3] => p )