Php preg_split error when switching from split to preg_split

I get this warning from php after changing from split to preg_split for php 5.3 compatibility:

PHP Warning:  preg_split(): Delimiter must not be alphanumeric or backslash

php code:

$statements = preg_split("\\s*;\\s*", $content);

How can I fix regex not to use anymore \

Thank!

+5
source share
3 answers

The error is that a delimiter character is required for a regular expression.

$statements = preg_split("/\s*;\s*/", $content);
+10
source

Although the question was marked as an answer two minutes after the request, I would like to add some information for the notes.

, , , Perl JavaScript, . :

/\s*;\s*/

:

/\s*;\s*/Ui

PHP Perl- (aka preg _... functions) . PHP , preg_split() /\s*;\s*/ . .

, , - , PHP . , :

@\s*;\s*@Ui

? , . :

/^\/home\/.*$/i
@^/home/.*$@i
+4

, T-Regx:

pattern("\\s*;\\s*")->split($content):

Pattern::of("\\s*;\\s*")->split()

0

All Articles