PhpDig.net

Go Back   PhpDig.net > General Forums > Coding & Tutorials

Reply
 
Thread Tools
Old 03-29-2007, 01: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
Old 03-29-2007, 01:35 PM   #2
Graphicgreen
Green Mole
 
Join Date: Mar 2007
Posts: 2
This is the output I get.

49 number of tokens
Bombers
Graphicgreen is offline   Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help using output as Array function ehdesign How-to Forum 0 09-16-2006 06:32 AM
Url part after &amp; is ignored on spider (1.8.9 RC1 and earliers) obottek Bug Tracker 1 08-24-2006 05:52 AM
Array variables in MySQL UPDATES peterl3233 Coding & Tutorials 4 11-10-2005 09:59 PM
Search Template/Array tomas How-to Forum 1 02-29-2004 12:24 AM


All times are GMT -8. The time now is 09:05 PM.


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