php preg_split error when switching from split to preg_split

benjisail picture benjisail · Feb 18, 2010 · Viewed 7.2k times · Source

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

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

the php code is :

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

How can I fix the regex to not use anymore \

Thanks!

Answer

Ben James picture Ben James · Feb 18, 2010

The error is because you need a delimiter character around your regular expression.

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