Jump to content

Get Page Source And Seperate Parts Into Variables


dzhax
 Share

Recommended Posts

I am working on a stat lookup for a game someone i know is developing.They have made a script that lists each stat information seperated by a comma (,) on a line. Being a new line for each stat. Is there a way in php to read the source of a page and seperate all values within the commas and the enters into an array.Sorta like the split statement in visual basic 6.Ex. Stat Page Source:627956,1263,12143677595955,75,1217048770780,70,759985830886,75,1218084828439,73,10829251840713,51,121556895793,49,93966343289,76,14042931364538,59,249705241171,83,2697608534281,71,838666853349,64,4314691141551,53,142135879664,52,135279313446,60,298509170875,73,1059601859627,30,143851451923,33,20021370131,55,168023-1,-1,-1-1,-1,-1800502,37,30407663862,36,27014243355,52,124984-1,-1,-1-1,-1-1,-1-1,-1-1,-1-1,-1majority of the page has 3 values for each stat except for the last 5 that only have two.a part of the link to the stat lookup that im pulling from is "index_lite.ws?player=ACCOUNT NAME"Thank you in advance for any help.

Link to comment
Share on other sites

PHP has an explode() function.
yea thats what i tried to use but i cant seem to make it work right...Maybe you can make me an example.This is what i have but i can only extract the first value not any more.
<?php$username = $_GET['username'];   $username = strtolower(str_replace(' ', '_', $username));$website = file_get_contents('http://dzhax.com/index_lite.ws?player=' . $username);$stats = explode("\n", $website);$overall = array_shift(explode(",", $stats[0]));$stat['att'] = array_shift(explode(",", $stats[1]));$stat['def'] = array_shift(explode(",", $stats[2]));$stat['str'] = array_shift(explode(",", $stats[3]));$stat['hp'] = array_shift(explode(",", $stats[4]));$stat['rng'] = array_shift(explode(",", $stats[5]));$stat['pry'] = array_shift(explode(",", $stats[6]));$stat['mag'] = array_shift(explode(",", $stats[7]));$stat['ck'] = array_shift(explode(",", $stats[8]));$stat['wc'] = array_shift(explode(",", $stats[9]));$stat['flt'] = array_shift(explode(",", $stats[10]));$stat['fsh'] = array_shift(explode(",", $stats[11]));$stat['fm'] = array_shift(explode(",", $stats[12]));$stat['cra'] = array_shift(explode(",", $stats[13]));$stat['smi'] = array_shift(explode(",", $stats[14]));$stat['min'] = array_shift(explode(",", $stats[15]));$stat['her'] = array_shift(explode(",", $stats[16]));$stat['ag'] = array_shift(explode(",", $stats[17]));$stat['th'] = array_shift(explode(",", $stats[18]));$stat['sl'] = array_shift(explode(",", $stats[19]));$stat['frm'] = array_shift(explode(",", $stats[20]));$stat['rc'] = array_shift(explode(",", $stats[21]));$stat['hun'] = array_shift(explode(",", $stats[22]));$stat['cs'] = array_shift(explode(",", $stats[23]));echo "Attack Exp: " . $stat['att'];?>

the website it is grabbing from is made by me for testing... so any acc name will work.there is no script to get the values its always the same.For further reference the first value is Experience points, the next is stat level, and the third is overall rank.Dont worry about the last 5 dont need them yet.Thank you.

Edited by dzhax
Link to comment
Share on other sites

You forgot to declare $stat as an array.
$stat = array();

i added that in but nothing changed.how would i just get the experience or level or just the rank.$exp['att'] = array(...$lvl['att'] = array(...$rank['att'] = array(...if i do
$stat['att'] = array_shift(explode(",", $stats[1],1));echo "Attack Exp: " . $stat['att'];
it displaysAttack Exp: 595990,75,1217075 if i do
$stat['att'] = array_shift(explode(",", $stats[1]));echo "Attack Exp: " . $stat['att'];
it displaysAttack Exp: 595990 Edited by dzhax
Link to comment
Share on other sites

I've put this together quickly, is this what you are looking for?<?php$filename = "test.txt";$content = file($filename);$listcount=0;foreach($content as $str){list($p01,$p02,$p03)=explode(",",$str); if($p01 != "") { $array[$listcount]=$p01; $listcount++; }if($p02 != "") { $array[$listcount]=$p02; $listcount++; }if($p03 != "") { $array[$listcount]=$p03; $listcount++; }}$total = count($array);for($i=0;$i<$total;$i++){echo $array[$i]."<br />";}?>

Edited by dsonesuk
Link to comment
Share on other sites

I think you're looking for this:

<?phpdefine('EXP', 0);define('LVL', 1);define('RANK', 2);$username = $_GET['username'];$username = strtolower(str_replace(' ', '_', $username));$website = file_get_contents('http://dzhax.com/index_lite.ws?player=' . $username);$stats = explode("\n", $website);$overall = explode(",", $stats[0]);$stat = array(  'att' => explode(",", $stats[1]),  'def' => explode(",", $stats[2]),  'str' => explode(",", $stats[3]),  'hp' => explode(",", $stats[4]),  'rng' => explode(",", $stats[5]),  'pry' => explode(",", $stats[6]),  'mag' => explode(",", $stats[7]),  'ck' => explode(",", $stats[8]),  'wc' => explode(",", $stats[9]),  'flt' => explode(",", $stats[10]),  'fsh' => explode(",", $stats[11]),  'fm' => explode(",", $stats[12]),  'cra' => explode(",", $stats[13]),  'smi' => explode(",", $stats[14]),  'min' => explode(",", $stats[15]),  'her' => explode(",", $stats[16]),  'ag' => explode(",", $stats[17]),  'th' => explode(",", $stats[18]),  'sl' => explode(",", $stats[19]),  'frm' => explode(",", $stats[20]),  'rc' => explode(",", $stats[21]),  'hun' => explode(",", $stats[22]),  'cs' => explode(",", $stats[23]));print_r($stat);echo "<br><br>Attack Exp: " . $stat['att'][EXP];echo "<br><br>Attack Level: " . $stat['att'][LVL];echo "<br><br>Attack Rank: " . $stat['att'][RANK];?>

Shifting an array is just going to remove and return the first element, but you're looking for all 3 right? So you would just explode each line, you don't need to shift off the first element.

Link to comment
Share on other sites

I think you're looking for this:
<?phpdefine('EXP', 0);define('LVL', 1);define('RANK', 2);$username = $_GET['username'];$username = strtolower(str_replace(' ', '_', $username));$website = file_get_contents('http://dzhax.com/index_lite.ws?player=' . $username);$stats = explode("\n", $website);$overall = explode(",", $stats[0]);$stat = array(  'att' => explode(",", $stats[1]),  'def' => explode(",", $stats[2]),  'str' => explode(",", $stats[3]),  'hp' => explode(",", $stats[4]),  'rng' => explode(",", $stats[5]),  'pry' => explode(",", $stats[6]),  'mag' => explode(",", $stats[7]),  'ck' => explode(",", $stats[8]),  'wc' => explode(",", $stats[9]),  'flt' => explode(",", $stats[10]),  'fsh' => explode(",", $stats[11]),  'fm' => explode(",", $stats[12]),  'cra' => explode(",", $stats[13]),  'smi' => explode(",", $stats[14]),  'min' => explode(",", $stats[15]),  'her' => explode(",", $stats[16]),  'ag' => explode(",", $stats[17]),  'th' => explode(",", $stats[18]),  'sl' => explode(",", $stats[19]),  'frm' => explode(",", $stats[20]),  'rc' => explode(",", $stats[21]),  'hun' => explode(",", $stats[22]),  'cs' => explode(",", $stats[23]));print_r($stat);echo "<br><br>Attack Exp: " . $stat['att'][EXP];echo "<br><br>Attack Level: " . $stat['att'][LVL];echo "<br><br>Attack Rank: " . $stat['att'][RANK];?>

Shifting an array is just going to remove and return the first element, but you're looking for all 3 right? So you would just explode each line, you don't need to shift off the first element.

Thanks ill try that. All that i had was working off an example i found. So i had no idea what shift_array ment or did------K i checked it...
print_r($stat);

is that needed? it just printed the array it looked weird. I commented it out and it looked ok. Was that ok?

Edited by dzhax
Link to comment
Share on other sites

Thanks ill try that. All that i had was working off an example i found. So i had no idea what shift_array ment or did------K i checked it...
print_r($stat);

is that needed? it just printed the array it looked weird. I commented it out and it looked ok. Was that ok?

Yep. I believe justsomeguy put it there just in case you have problems. If you had, you'd tell us what the output was (along with the print_r() output), and it would be easier for us to help.Consider searching the php.net site when you're wondering what a function does.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...