[ trim ]This stumped me badly in my present project. Is this a bug or a feature in PHP? I am trying to split a string into two, where only one half (and the delimiter) is present.
IN PHP =======================
[EMAIL PROTECTED] ~]$ cat s1.php <?php print count(split(',', 'a,b'))."\n"; print count(split(',', 'a,'))."\n"; ?>
[EMAIL PROTECTED] sql]$ php -q s1.php 2 2
If your expand your example slightly, as I did, you will see why you are getting the expected results:
[EMAIL PROTECTED] burhan $ cat s1.php <?php $results = split(',', 'a,b'); print_r($results); print count($results)."\n";
$results = split(',','a,'); print_r($results); print count($results)."\n";
?> [EMAIL PROTECTED] burhan $ php -q s1.php Array ( [0] => a [1] => b ) 2 Array ( [0] => a [1] => ) 2
As you can see, the array contains an empty second element because (correctly) there isn't a second element after the last ,.
So, is this a bug? Not from my point of view. Its more bad input, expected result :)
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php