return empty string from preg_split

Posted by Gutzofter on Stack Overflow See other posts from Stack Overflow or by Gutzofter
Published on 2010-04-22T20:34:16Z Indexed on 2010/04/22 20:43 UTC
Read the original article Hit count: 264

Filed under:
|
|

Right now i'm trying to get this:

Array
(
    [0] => hello
    [1] => 
    [2] => goodbye
)

Where index 1 is the empty string.

$toBeSplit= 'hello,,goodbye';

$textSplitted = preg_split('/[,]+/', $toBeSplit, -1);

$textSplitted looks like this:

Array
(
    [0] => hello
    [1] => goodbye
)

I'm using PHP 5.3.2

© Stack Overflow or respective owner

Related posts about regex

Related posts about php