Hi, Thanks for all who responded, and the function is now working properly. It turned out that count function works for strings that contain the actual data inside, but when it is an empty string, a new if clause had to be set to create the count. Alice Alice Wei Indiana University, MIS 2008 Programmer/Computer Application Developer ProCure Treatment Centers, Inc. 420 N. Walnut St. Bloomington, IN 47404 812-330-6644 (office) 812-219-5708 (mobile) Alice.Wei@xxxxxxxxxxxxxxxxxx(email) http://www.procurecenters.com/index.php (web) ---------------------------------------- > Date: Fri, 31 Oct 2008 17:00:44 +0000 > From: dafneves@xxxxxxxxx > To: danbrown@xxxxxxx > CC: ajwei@xxxxxxxxxxxxx; php-general@xxxxxxxxxxxxx > Subject: Re: Count the Number of Elements Using Explode > > Hi Alice, > > U can simple do: > $nr = ( strlen( $message ) / 2 ) + 1 ); > $nr = count( explode( '|', $message ); > > On Fri, Oct 31, 2008 at 4:32 PM, Daniel Brown wrote: > >> On Fri, Oct 31, 2008 at 11:29 AM, Alice Wei wrote: >>> >>> Hi, >>> >>> I have a code snippet here as follows: >>> >>> $message="1|2|3|4|5"; >>> $stringChunks = explode("|", $message); >>> >>> Is it possible to find out the number of elements in this string? It >> seems that I could do things like print_r and find out what is the last >> element of $stringChunks is, but is there a way where I can use code from >> the two lines and have it print out 5 as the number of elements that >> contains after the splitting? >> >> http://php.net/strlen >> http://php.net/count >> >> -- >> >> http://www.parasane.net/ >> daniel.brown@xxxxxxxxxxxx || danbrown@xxxxxxx >> Ask me about our current hosting/dedicated server deals! >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > -- > Thanks, > > Diogo Neves > Web Developer @ SAPO.pt by PrimeIT.pt _________________________________________________________________ Check the weather nationwide with MSN Search: Try it now! http://search.msn.com/results.aspx?q=weather&FORM=WLMTAG -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php