View Single Post
Old 03-29-2007, 12:34 PM   #1
Graphicgreen
Green Mole
 
Join Date: Mar 2007
Posts: 2
explode & array issues

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

<?PHP
//echo $_REQUEST['Data'];
$string=$_REQUEST['Data'];
$stringpart = explode(" ",$string);
$stringcount=count($stringpart);
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)){
if($Stringpart[$location+1]="Bombers"){
echo "Heavy Bombers ";}
}

if(in_array("Ion", $stringpart)){
if($Stringpart[$location+1]="Bombers"){
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>";
}
PHP>

This is the Data I input into the form

Units
Fighters 1000
Bombers 460
Heavy Bombers 300
Corvette 267
Recycler 145
Graphicgreen is offline   Reply With Quote