4
$date could be "23/09/2012" or "23-09-2012" or "23\09\2012"
preg_split('/[\/\-\\]/', $date);
不确定为什么PHP继续抛出missing terminating ] error
?编译失败:缺失终止]字符分类
$date could be "23/09/2012" or "23-09-2012" or "23\09\2012"
preg_split('/[\/\-\\]/', $date);
不确定为什么PHP继续抛出missing terminating ] error
?编译失败:缺失终止]字符分类
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)
@Xin Chen:我的正则表达式有一个错误,因为它不是在'\\'分裂。请参阅最新的答案。 –
你需要逃避连字符? –
@Xin旧的正则表达式中有一个错误。请参阅最新的答案。对于那个很抱歉。 –