RE: [PHP] explode()

From: Date: Mon, 17 Nov 2003 20:37:09 +0000
Subject: RE: [PHP] explode()
Groups: php.general 
Request: Send a blank email to php-general+get-170003@lists.php.net to get a copy of this message
[snip] I am having a user enter a phrase into a textbox, and then I need to seperate the words he has typed into variables so I can use each one in an sql statement. I know I will use the explode() function to do this, but how will I know how many variables I've created. For instance, if a user types in 3 words seperated by spaces, how will I know i'll have var[0] through var[2]? how about when they type in 2 words or 4 words? How will I know how many words they have typed in? The only way I can think of to do this is: [/snip] Use count() http://www.php.net/count Counts the array ... $arrayFoo = explode(" ", $theLine); $countFoo = count($arrayFoo); for($i = 0; $i < $countFoo; $i++){ echo $arrayFoo[$i]; }

« previous php.general (#170003) next »