ID:               38912
 Updated by:       [EMAIL PROTECTED]
 Reported By:      barry dot wills at providence dot org
-Status:           Open
+Status:           Bogus
 Bug Type:         PCRE related
 Operating System: Red Hat Fedora Core 4
 PHP Version:      5.1.6
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

To avoid empty matches you need to pass the 
PREG_SPLIT_NO_EMPTY flag to preg_split().


Previous Comments:
------------------------------------------------------------------------

[2006-09-21 14:11:31] barry dot wills at providence dot org

Description:
------------
preg_split('/\s/', '') is used to split a string whose fields are
delimited by whitespace chars. When the string is empty (""),
preg_split returns a populated array rather than an empty array.

Expected: the equivalent in Perl returns an empty array (split(/\s/,
'')).

Unexpected: preg_split in PHP returns a populated array.

Reproduce code:
---------------
// Example 1 produces: Array ( [0] => )
$a = preg_split('/\s/', '');
print_r($a);

// Example 2 produces: Array ( [0] => )
$a = preg_split('/\s+/', '');
print_r($a);

// Example 3 produces: Array ( [0] => [1] => ) 
$a = preg_split('/\s*/', '');
print_r($a);

// Perl produces an empty array in all three cases.

Expected result:
----------------
No output. Which is to say, the above code should be equivalent to
PHP's:

$a = array();

Actual result:
--------------
Array ( [0] => )
Array ( [0] => )
Array ( [0] => [1] => )



------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=38912&edit=1

Reply via email to