PhpDig.net

PhpDig.net (http://www.phpdig.net/forum/index.php)
-   Coding & Tutorials (http://www.phpdig.net/forum/forumdisplay.php?f=31)
-   -   explode & array issues (http://www.phpdig.net/forum/showthread.php?t=2760)

Graphicgreen 03-29-2007 12:34 PM

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 03-29-2007 12:35 PM

This is the output I get.

49 number of tokens
Bombers


All times are GMT -8. The time now is 04:18 AM.

Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.