split behaviour differences in perl and php
| From: | Sandip Bhattacharya | Date: | Thu, 16 Sep 2004 09:49:11 +0000 |
| Subject: | split behaviour differences in perl and php | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-196846@lists.php.net to get a copy of this message | ||
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 PERL
==================================
[sandip@pluto ~]$ cat s1.pl
@t = split(/,/ , "a,b");
$len = $#t + 1;
print "$len\n";
@t = split(/,/, "a,");
$len = $#t + 1;
print "$len\n";
[sandip@pluto sql]$ perl s1.pl
2
1
IN PHP
=======================
[sandip@pluto ~]$ cat s1.php
<?php
print count(split(',', 'a,b'))."\n";
print count(split(',', 'a,'))."\n";
?>
[sandip@pluto sql]$ php -q s1.php
2
2
--
Sandip Bhattacharya * Puroga Technologies * sandip@puroga.com
Work: http://www.puroga.com * Home: http://www.sandipb.net
PGP/GPG Signature: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3
BLISS is ignorance.