From: barry dot wills at providence dot org
Operating system: Red Hat Fedora Core 4
PHP version: 5.1.6
PHP Bug Type: PCRE related
Bug description: preg_split('/\s+/', '') returns an array of length one
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 bug report at http://bugs.php.net/?id=38912&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=38912&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=38912&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=38912&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=38912&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=38912&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=38912&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=38912&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=38912&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=38912&r=support
Expected behavior: http://bugs.php.net/fix.php?id=38912&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=38912&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=38912&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=38912&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=38912&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=38912&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=38912&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=38912&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=38912&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=38912&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=38912&r=mysqlcfg