* Thus wrote Sandip Bhattacharya:
> 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
> ==================================
> [EMAIL PROTECTED] ~]$ cat s1.pl
> @t = split(/,/ , "a,b");
> $len = $#t + 1;
> print "$len\n";
> @t = split(/,/, "a,");
> $len = $#t + 1;
> print "$len\n";
> 
> [EMAIL PROTECTED] sql]$ perl s1.pl
> 2
> 1
> 
> 
> 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

split in php isn't the same as perl's split, there is preg_split()
which you can use:

  $results = preg_split('/,/','a,', -1, PREG_SPLIT_NO_EMPTY);
  print(count($results)); //  outputs: 1


Curt
-- 
The above comments may offend you. flame at will.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to