|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-09-24 17:46 UTC] iliaa@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 09:00:01 2025 UTC |
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] => )