[thelist] preg_split in PHP

alpha at student.uci.agh.edu.pl alpha at student.uci.agh.edu.pl
Tue Jan 15 03:36:06 CST 2002


On Mon, Jan 14, 2002 at 11:29:50PM -0500, noah wrote:
> It worked, but I still wasn't able to count the characters properly
> (preg_split was still acting funny, and count_chars() seems to have emerged

Thats where strlen() could be helpful :)

> I'm still curious about why when I did:
> 
> $acts = preg_split('//', '2457');
> $number_of_acts = (count($acts));
> 
> $number_of_acts came back as 6.

Because it also splits beginning and end of the string - and they give
empty array elements, so you should use:

$acts = preg_split('//', '2457', -1, PREG_SPLIT_NO_EMPTY);

Notice -1 as the third argument!!


-- 

   _.|._ |_  _.  |  Adam Byrtek, alpha at irc.pl
  (_|||_)| |(_|  |  gg 1802819
      |             




More information about the thelist mailing list