Compilation error: missing completion] for character class

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

Not sure why PHP keeps throwing missing terminating ] error ?

+4
source share
1 answer
 preg_split('/[\/\-\\]/', $date); ^escaping the closing ']' 

Follow these steps to resolve the ambiguity.

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

You do not need to run - , but you can also use \- .


code:

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

Output:

 Array ( [0] => as [1] => sad [2] => s [3] => p ) 
+8
source

Source: https://habr.com/ru/post/1443388/


All Articles