5
$date could be "23/09/2012" or "23-09-2012" or "23\09\2012" 
preg_split('/[\/\-\\]/', $date);

不知道为什么 PHP 保持抛出missing terminating ] error

4

1 回答 1

13
preg_split('/[\/\-\\]/', $date);
                   ^escaping the closing ']' 

请改为执行以下操作,以消除歧义

preg_split('/[\/\-\\\\]/', $date);

没有必要 escape -,但你也可以使用\-


代码:

$date = 'as\sad-s/p';
$slices =  preg_split('/[\/\-\\\\]/', $date);
print_r($slices);

输出:

Array ( [0] => as [1] => sad [2] => s [3] => p )
于 2012-11-01T09:10:29.480 回答