hello all. im fairly new to PHP and i cannot get this code to work what so ever. First, lemme explain what the code is supposed to do. First it goes to a site, retrives the hiscores of a certain person for this game. Then, it is SUPPOSED to display them on a page that i have created. however, i cant get it to display.
The game is runescape, and the site is http://hiscore.runescape.com/index_lite.ws?player=ddrght12345 these are my stats.
It basically reads left to right, The skills seperated by spaces. then Rank on the hiscores, current level of the skill, and current experience I have in that skill seperated by commas (respectivefully). anything with "-1" in the lite version, means im not ranked in that skill.
If you would like to see how RuneScape themselves display the stats, http://hiscore.runescape.com/hiscorepersonal.ws?user1=ddrght12345
this code is supposed to display the lite version in an easier layout to read. now the code:
<?php
$player = 'ddrght12345';
// To get player name from address bar, uncomment following lines
//$player = str_replace(' ', '%20', $_GET['name']);
//$player = preg_replace('/[^a-zA-Z0-9%]/', '', $player);
$readstats = file_get_contents('http://hiscore.runescape.com/index_lite.ws?player=' . $player);
if (!$readstats)
{
die('Error: Invalid name');
}
// Get arrays of stats and stat names
$readstats = explode(' ', $readstats);
// Set up main array
$stats = array("Overall", "Attack", "Defence", "Strength", "Hitpoints", "Ranged", "Prayer", "Magic", "Cooking", "Woodcutting", "Fletching", "Fishing", "Firemaking", "Crafting", "Smithing", "Mining", "Herblore", "Agility", "Thieving", "Slayer", "Farming", "Runecraft", "Hunter", "Construction", "Summoning", "DT", "BH", "BHR", "FoG");
// Combine them
$i = 0;
foreach ($stats AS $key => $value)
{
if ($value != -1)
{
echo $stats[$key] = explode(',', $readstats[$i]);
}
$i++;
}
/* FOR STATS
$stats['name'][0] = Rank
$stats['name'][1] = Level
$stats['name'][2] = Exp
*/
/* FOR MINIGAMES
$stats['name'][0] = Rank
$stats['name'][1] = Points
*/
/* Examples
Woodcutting level:
echo $stats['Woodcutting'][1];
Fist of Guthix rank:
echo $stats['FoG'][0];
Summoning Exp:
echo $stats['Summoning'][2];
*/
echo "Fishing Stats:<BR>";
echo "Rank: ";
echo $stats['Fishing'][0];
echo "<br> Level: ";
echo $stats['Fishing'][1];
echo "<br> Current Exp: ";
echo $stats['Fishing'][2];
echo "<br><br>";
echo "Prayer Stats:<BR>";
echo "Rank: ";
echo $stats['Prayer'][0];
echo "<br> Level: ";
echo $stats['Prayer'][1];
echo "<br> Current Exp: ";
echo $stats['Prayer'][2];
echo "<br><br>";
echo "Magic Stats:<BR>";
echo "Rank: ";
echo $stats['Magic'][0];
echo "<br> Level: ";
echo $stats['Magic'][1];
echo "<br> Current Exp: ";
echo $stats['Magic'][2];
echo "<br><br>";
echo "Cooking Stats:<BR>";
echo "Rank: ";
echo $stats['Cooking'][0];
echo "<br> Level: ";
echo $stats['Cooking'][1];
echo "<br> Current Exp: ";
echo $stats['Cooking'][2];
?>
if anyone could tell me exactly what im doing wrong and possibly even correct my code, that would be awesome. plus, if someone could show me how to make it so that if im not ranked in a skill, then i could display "not ranked" or "--" instead.
also im up for critism for cleaning my code