View Full Version : explode & array issues

03-29-2007, 12:34 PM
I'm kind of new to PHP, I managed to get a form to break the input up into pieces with the explode command. Mind you it doesn't work with all the input I've tried (sometimes I get lines with / 2 (when the original input was 2 / 2) Anyway. Is there a better method of breaking up a large chunk of information?

Also, when I run this code, the first IF statement works, but the second does not and the third does. The rest seem to be ignored.
I've tried using 'current($array) and next($array)' but I end up getting error messages with that. (I'm trying to move the pointer up, to retrieve the expected information)

I'm thinking i should try a different method other then an array (I've done string manipulation in Coldfusion just fine, just figured I'd learn arrays in PHP)

This is the PHP code I'm running

//echo $_REQUEST['Data'];
$stringpart = explode(" ",$string);
echo $stringcount." number of tokens";
echo "<BR>";

if(in_array("Units", $stringpart)){

if(in_array("Fighters", $stringpart)){
echo "Fighter ";

if(in_array("Bombers", $stringpart)){
echo "Bombers ";

if(in_array("Heavy", $stringpart)){
echo "Heavy Bombers ";}

if(in_array("Ion", $stringpart)){
echo "Ion Bombers ";}

if(in_array("Corvette", $stringpart)){
echo "Corvette ";

if(in_array("Recycler", $stringpart)){
echo "Recycler ";

if(in_array("Destroyer", $stringpart)){
echo "Destroyer ";

else {
echo "<B>You have not entered a fleet page</B>";

This is the Data I input into the form

Fighters 1000
Bombers 460
Heavy Bombers 300
Corvette 267
Recycler 145

03-29-2007, 12:35 PM
This is the output I get.

49 number of tokens