Compilation failed: missing terminating ] for character class

后端 未结 1 887
慢半拍i
慢半拍i 2021-01-03 02:49
$date could be \"23/09/2012\" or \"23-09-2012\" or \"23\\09\\2012\" 
preg_split(\'/[\\/\\-\\\\]/\', $date);

Not sure why PHP keep throw missi

相关标签:
1条回答
  • 2021-01-03 03:01
    preg_split('/[\/\-\\]/', $date);
                       ^escaping the closing ']' 
    

    Do the following instead, to remove ambiguity

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

    There is no need to escape -, but you could use \- as well.


    Code:

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

    Output:

    Array ( [0] => as [1] => sad [2] => s [3] => p )
    
    0 讨论(0)
提交回复
热议问题