![]() |
|
![]() |
#1 |
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 |
![]() |
![]() |
![]() |
#2 |
Green Mole
Join Date: Mar 2007
Posts: 2
|
This is the output I get.
49 number of tokens Bombers |
![]() |
![]() |
![]() |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Help using output as Array function | ehdesign | How-to Forum | 0 | 09-16-2006 05:32 AM |
Url part after & is ignored on spider (1.8.9 RC1 and earliers) | obottek | Bug Tracker | 1 | 08-24-2006 04:52 AM |
Array variables in MySQL UPDATES | peterl3233 | Coding & Tutorials | 4 | 11-10-2005 08:59 PM |
Search Template/Array | tomas | How-to Forum | 1 | 02-28-2004 11:24 PM |