how would i...
Moderator: General Moderators
how would i...
be able to 'parse' a .txt file into different parts
Click Here
above is and example for stats of a game
each 'clan' is separated by a '*' and each stat is separated by a ","
Click Here
above is and example for stats of a game
each 'clan' is separated by a '*' and each stat is separated by a ","
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
oops! my bad! [php_man]fopen()[/php_man] Also look at all the other file opening functions. Look around the forum and internet also on hwo to open file with PHP. after you've got the file opened, here is som code for you to play around with:
Code: Select all
<?php
//I just copied everything from that text file and put it into a string
$string = "BomB,10262048,77295,23404,1820,397,36*ICW,9079253,62912,21642,2163,322,26*LNo,6807445,45531,16173,1180,151,27*DMW,6647833,43558,16017,1170,149,51*NF,6165175,51434,13709,1055,444,81*CAT,6157036,45272,13588,930,165,29*GOD,5355379,50370,12293,1636,624,58*XLT,5148893,34200,12864,913,151,43*BiB,4455928,33585,10037,673,285,9*BnX,4389378,29339,10975,1002,61,31*WST,4261557,32581,10321,1261,277,40*HiS,4216139,30490,9991,571,86,27*ARMY,2473189,22572,5053,359,281,47*EPP,1491750,10736,3600,289,77,25*MOB,1129248,13549,2564,410,244,48*FaB,999367,7837,2166,102,52,22*USA,783133,6113,1814,125,33,16*FUA,534341,10290,1606,424,554,35*LDC,495464,4432,1199,73,36,10*TFA,437496,2866,998,68,8,6*PPP,347358,3096,821,52,28,2*GOAT,224592,2229,504,37,39,22*GAT,100949,923,279,17,5,8*MFB,98567,2139,310,44,187,14*NONE,45564,3093,369,58,232,35*DTP,38145,387,95,7,4,6*WAR,21408,161,57,4,0,10*9NjA,11815,198,32,3,15,3*bleu,6484,55,13,0,1,6*31,123,2,0,0,0,1*";
$clan = explode("*", $string);
foreach($clan as $val){
$stats[] = explode(",",$val);
}
echo "<pre>";
print_r($stats);
echo "</pre>";
?>-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
actually, since your opening from a url, you might find it easier/better to use [php_man]file()[/php_man].
Here try this, i got it to work. It open that text file, reads it into $string, then each element of the main array is a clan and the sub-elements are the clan stats. If that amde any sense...
Here try this, i got it to work. It open that text file, reads it into $string, then each element of the main array is a clan and the sub-elements are the clan stats. If that amde any sense...
Code: Select all
<?php
$string = file("http://www.gettiffany.com/groups.txt"); //open the textfile
$string = $string[0]; //its only one line, so get the first line
$clan = explode("*", $string); //explode is pretty much same as split
foreach($clan as $val){ //loop through each clan
$stats[] = explode(",",$val); //and 'explode' the stats!
}
echo "<pre>"; //formatting to make it easier to read
print_r($stats); //print the stats array
echo "</pre>";
?>i get something like this
but instead of having the
[0] => BomB
[1] => 10262048
[2] => 77295
[3] => 23404
[4] => 1820
[5] => 397
[6] => 36
instead of [0] for it to be Short name of group
and instead of [1] for it to be Points
[2] to be Games Played
[3] to be Games won
[4] to be Zeros
[5] to be Got zeroed
and [6] be Number of members
if that is possible
im guessing on this but , maybe this line could be something like
Code: Select all
Array
(
ї0] => Array
(
ї0] => BomB
ї1] => 10262048
ї2] => 77295
ї3] => 23404
ї4] => 1820
ї5] => 397
ї6] => 36
)[0] => BomB
[1] => 10262048
[2] => 77295
[3] => 23404
[4] => 1820
[5] => 397
[6] => 36
instead of [0] for it to be Short name of group
and instead of [1] for it to be Points
[2] to be Games Played
[3] to be Games won
[4] to be Zeros
[5] to be Got zeroed
and [6] be Number of members
if that is possible
im guessing on this but , maybe this line could be something like
Code: Select all
$string = $string['Short name of group','Points','Games Played','Games Won','Zeros','Got Zerod','Number of members'];-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
You could do this (i think)
Code: Select all
<?php
$fields = array(
'Short name of Group',
'Points',
'Games Played',
'Games Won',
'Zeros',
'Got Zeroed',
'Number of Members'
);
$clans = explode('*', file_get_contents('http://www.gettiffany.com/groups.txt'));
$count = 0;
foreach($clans as $clan){
$parts = explode(',', $clan);
$total = count($parts);
for($x=0;$x<$total;$x++){
$output[$count][$fields[$x]] = $parts[$x];
}
$count++;
}
var_dump($output); //testing
echo '<br />'.$output[3]['Short name of Group']; //another test
?>-
Illusionist
- Forum Regular
- Posts: 903
- Joined: Mon Jan 12, 2004 9:32 pm
all i get is a bunch of nonsense
Code: Select all
array(32) { ї0]=> array(7) { ї"Short name of Group"]=> string(4) "BomB" ї"Points"]=> string(8) "10319814" ї"Games Played"]=> string(5) "77725" ї"Games Won"]=> string(5) "23548" ї"Zeros"]=> string(4) "1827" ї"Got Zeroed"]=> string(3) "402" ї"Number of Members"]=> string(2) "34" } ї1]=> array(7) { ї"Short name of Group"]=> string(3) "ICW" ї"Points"]=> string(7) "9117444" ї"Games Played"]=> string(5) "63183" ї"Games Won"]=> string(5) "21726" ї"Zeros"]=> string(4) "2169" ї"Got Zeroed"]=> string(3) "325" ї"Number of Members"]=> string(2) "26" } ї2]=> array(7) { ї"Short name of Group"]=> string(3) "LNo" ї"Points"]=> string(7) "6875353" ї"Games Played"]=> string(5) "45959" ї"Games Won"]=> string(5) "16340" ї"Zeros"]=> string(4) "1194" ї"Got Zeroed"]=> string(3) "152" ї"Number of Members"]=> string(2) "25" } ї3]=> array(7) { ї"Short name of Group"]=> string(3) "DMW" ї"Points"]=> string(7) "6700591" ї"Games Played"]=> string(5) "43932" ї"Games Won"]=> string(5) "16135" ї"Zeros"]=> string(4) "1179" ї"Got Zeroed"]=> string(3) "153" ї"Number of Members"]=> string(2) "52" } ї4]=> array(7) { ї"Short name of Group"]=> string(2) "NF" ї"Points"]=> string(7) "6342997" ї"Games Played"]=> string(5) "52770" ї"Games Won"]=> string(5) "14103" ї"Zeros"]=> string(4) "1095" ї"Got Zeroed"]=> string(3) "456" ї"Number of Members"]=> string(2) "83" } ї5]=> array(7) { ї"Short name of Group"]=> string(3) "CAT" ї"Points"]=> string(7) "6175338" ї"Games Played"]=> string(5) "45424" ї"Games Won"]=> string(5) "13622" ї"Zeros"]=> string(3) "932" ї"Got Zeroed"]=> string(3) "166" ї"Number of Members"]=> string(2) "31" } ї6]=> array(7) { ї"Short name of Group"]=> string(3) "GOD" ї"Points"]=> string(7) "5363640" ї"Games Played"]=> string(5) "50467" ї"Games Won"]=> string(5) "12317" ї"Zeros"]=> string(4) "1636" ї"Got Zeroed"]=> string(3) "629" ї"Number of Members"]=> string(2) "57" } ї7]=> array(7) { ї"Short name of Group"]=> string(3) "XLT" ї"Points"]=> string(7) "5205374" ї"Games Played"]=> string(5) "34549" ї"Games Won"]=> string(5) "13001" ї"Zeros"]=> string(3) "925" ї"Got Zeroed"]=> string(3) "153" ї"Number of Members"]=> string(2) "44" } ї8]=> array(7) { ї"Short name of Group"]=> string(3) "BiB" ї"Points"]=> string(7) "4485019" ї"Games Played"]=> string(5) "33769" ї"Games Won"]=> string(5) "10107" ї"Zeros"]=> string(3) "677" ї"Got Zeroed"]=> string(3) "287" ї"Number of Members"]=> string(1) "9" } ї9]=> array(7) { ї"Short name of Group"]=> string(3) "BnX" ї"Points"]=> string(7) "4392847" ї"Games Played"]=> string(5) "29367" ї"Games Won"]=> string(5) "10985" ї"Zeros"]=> string(4) "1002" ї"Got Zeroed"]=> string(2) "61" ї"Number of Members"]=> string(2) "31" } ї10]=> array(7) { ї"Short name of Group"]=> string(3) "WST" ї"Points"]=> string(7) "4282069" ї"Games Played"]=> string(5) "32716" ї"Games Won"]=> string(5) "10374" ї"Zeros"]=> string(4) "1268" ї"Got Zeroed"]=> string(3) "278" ї"Number of Members"]=> string(2) "40" } ї11]=> array(7) { ї"Short name of Group"]=> string(3) "HiS" ї"Points"]=> string(7) "4230438" ї"Games Played"]=> string(5) "30599" ї"Games Won"]=> string(5) "10020" ї"Zeros"]=> string(3) "573" ї"Got Zeroed"]=> string(2) "86" ї"Number of Members"]=> string(2) "27" } ї12]=> array(7) { ї"Short name of Group"]=> string(3) "NBK" ї"Points"]=> string(7) "2710744" ї"Games Played"]=> string(3) "160" ї"Games Won"]=> string(2) "45" ї"Zeros"]=> string(1) "3" ї"Got Zeroed"]=> string(1) "1" ї"Number of Members"]=> string(2) "10" } ї13]=> array(7) { ї"Short name of Group"]=> string(4) "ARMY" ї"Points"]=> string(7) "2520612" ї"Games Played"]=> string(5) "22901" ї"Games Won"]=> string(4) "5156" ї"Zeros"]=> string(3) "363" ї"Got Zeroed"]=> string(3) "285" ї"Number of Members"]=> string(2) "50" } ї14]=> array(7) { ї"Short name of Group"]=> string(3) "EPP" ї"Points"]=> string(7) "1493730" ї"Games Played"]=> string(5) "10748" ї"Games Won"]=> string(4) "3605" ї"Zeros"]=> string(3) "289" ї"Got Zeroed"]=> string(2) "77" ї"Number of Members"]=> string(2) "25" } ї15]=> array(7) { ї"Short name of Group"]=> string(3) "MOB" ї"Points"]=> string(7) "1142245" ї"Games Played"]=> string(5) "13714" ї"Games Won"]=> string(4) "2577" ї"Zeros"]=> string(3) "415" ї"Got Zeroed"]=> string(3) "253" ї"Number of Members"]=> string(2) "50" } ї16]=> array(7) { ї"Short name of Group"]=> string(3) "FaB" ї"Points"]=> string(7) "1045538" ї"Games Played"]=> string(4) "8203" ї"Games Won"]=> string(4) "2259" ї"Zeros"]=> string(3) "105" ї"Got Zeroed"]=> string(2) "52" ї"Number of Members"]=> string(2) "19" } ї17]=> array(7) { ї"Short name of Group"]=> string(3) "USA" ї"Points"]=> string(6) "782255" ї"Games Played"]=> string(4) "6139" ї"Games Won"]=> string(4) "1817" ї"Zeros"]=> string(3) "125" ї"Got Zeroed"]=> string(2) "33" ї"Number of Members"]=> string(2) "16" } ї18]=> array(7) { ї"Short name of Group"]=> string(3) "FUA" ї"Points"]=> string(6) "535327" ї"Games Played"]=> string(5) "10322" ї"Games Won"]=> string(4) "1612" ї"Zeros"]=> string(3) "426" ї"Got Zeroed"]=> string(3) "558" ї"Number of Members"]=> string(2) "33" } ї19]=> array(7) { ї"Short name of Group"]=> string(3) "911" ї"Points"]=> string(6) "517056" ї"Games Played"]=> string(4) "4536" ї"Games Won"]=> string(4) "1220" ї"Zeros"]=> string(2) "90" ї"Got Zeroed"]=> string(2) "28" ї"Number of Members"]=> string(2) "16" } ї20]=> array(7) { ї"Short name of Group"]=> string(3) "CoP" ї"Points"]=> string(6) "507094" ї"Games Played"]=> string(4) "4525" ї"Games Won"]=> string(4) "1224" ї"Zeros"]=> string(2) "74" ї"Got Zeroed"]=> string(2) "36" ї"Number of Members"]=> string(1) "8" } ї21]=> array(7) { ї"Short name of Group"]=> string(3) "TFA" ї"Points"]=> string(6) "438424" ї"Games Played"]=> string(4) "2874" ї"Games Won"]=> string(3) "999" ї"Zeros"]=> string(2) "68" ї"Got Zeroed"]=> string(1) "8" ї"Number of Members"]=> string(1) "5" } ї22]=> array(7) { ї"Short name of Group"]=> string(3) "PPP" ї"Points"]=> string(6) "347358" ї"Games Played"]=> string(4) "3096" ї"Games Won"]=> string(3) "821" ї"Zeros"]=> string(2) "52" ї"Got Zeroed"]=> string(2) "28" ї"Number of Members"]=> string(1) "2" } ї23]=> array(7) { ї"Short name of Group"]=> string(4) "GOAT" ї"Points"]=> string(6) "234323" ї"Games Played"]=> string(4) "2319" ї"Games Won"]=> string(3) "525" ї"Zeros"]=> string(2) "40" ї"Got Zeroed"]=> string(2) "41" ї"Number of Members"]=> string(2) "28" } ї24]=> array(7) { ї"Short name of Group"]=> string(3) "GAT" ї"Points"]=> string(6) "110640" ї"Games Played"]=> string(3) "991" ї"Games Won"]=> string(3) "305" ї"Zeros"]=> string(2) "18" ї"Got Zeroed"]=> string(1) "6" ї"Number of Members"]=> string(1) "8" } ї25]=> array(7) { ї"Short name of Group"]=> string(3) "MFB" ї"Points"]=> string(5) "98567" ї"Games Played"]=> string(4) "2139" ї"Games Won"]=> string(3) "310" ї"Zeros"]=> string(2) "44" ї"Got Zeroed"]=> string(3) "187" ї"Number of Members"]=> string(2) "13" } ї26]=> array(7) { ї"Short name of Group"]=> string(4) "NONE" ї"Points"]=> string(5) "44683" ї"Games Played"]=> string(4) "3126" ї"Games Won"]=> string(3) "370" ї"Zeros"]=> string(2) "58" ї"Got Zeroed"]=> string(3) "235" ї"Number of Members"]=> string(2) "33" } ї27]=> array(7) { ї"Short name of Group"]=> string(3) "DTP" ї"Points"]=> string(5) "40716" ї"Games Played"]=> string(3) "408" ї"Games Won"]=> string(3) "102" ї"Zeros"]=> string(1) "7" ї"Got Zeroed"]=> string(1) "4" ї"Number of Members"]=> string(1) "6" } ї28]=> array(7) { ї"Short name of Group"]=> string(3) "WAR" ї"Points"]=> string(5) "36503" ї"Games Played"]=> string(3) "270" ї"Games Won"]=> string(2) "91" ї"Zeros"]=> string(1) "8" ї"Got Zeroed"]=> string(1) "0" ї"Number of Members"]=> string(1) "8" } ї29]=> array(7) { ї"Short name of Group"]=> string(4) "9NjA" ї"Points"]=> string(5) "14174" ї"Games Played"]=> string(3) "216" ї"Games Won"]=> string(2) "40" ї"Zeros"]=> string(1) "3" ї"Got Zeroed"]=> string(2) "15" ї"Number of Members"]=> string(1) "3" } ї30]=> array(7) { ї"Short name of Group"]=> string(2) "31" ї"Points"]=> string(3) "123" ї"Games Played"]=> string(1) "2" ї"Games Won"]=> string(1) "0" ї"Zeros"]=> string(1) "0" ї"Got Zeroed"]=> string(1) "0" ї"Number of Members"]=> string(1) "3" } ї31]=> array(1) { ї"Short name of Group"]=> string(0) "" } }
DMW