porzant Posted July 27, 2007 Share Posted July 27, 2007 This is the page information is being called from: http://hiscore.runescape.com/hiscoreperson...s?user1=PorzantIf all of the fields are filled in, it works fine.If some (or all) fields are empty such as: http://hiscore.runescape.com/hiscorepersonal.ws?Nothing displays except for the Overall. If the field is empty, I want it to still display, just be blank. I think the problem is in the parse() function somewhere. This is the code I'm using: <html><head><title>RuneScape Stats for <?php echo $_GET[username]; ?></title><style type="text/css">body { font-family:Arial }</style></head><body><form method="get"><input type="text" name="username" maxlength="12" value="Username" onfocus="this.value=''" /> Rank:<input type="checkbox" name="rank" /><input type="submit" value="Stats" /></form><?php$contents = "";$handle = fopen("http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=".$_GET["username"],"r"); if($handle){ while (!feof($handle)) { $contents .= fread($handle, 8192); } fclose($handle);}function parse($skill_name){ global $contents; $matches = array(); $pattern = "@<tr>\\s<td.*><img.*></td>\\s<td.*><a.*>\\s" . $skill_name . "\\s</a></td>\\s<td.*>([0-9,\\s]*)</td>\\s<td.*>([0-9,\\s]*)</td>\\s<td.*>([0-9,\\s]*)</td>\\s</tr>@imsU"; $match_found = preg_match($pattern, $contents, $matches); $retval = array(); if ($match_found && $matches[1] != "") $retval['rank'] = $matches[1]; else $retval['rank'] = "--"; if ($match_found && $matches[2] != "") $retval['level'] = $matches[2]; else $retval['level'] = "--"; if ($match_found && $matches[3] != "") $retval['xp'] = $matches[3]; else $retval['xp'] = "--"; return $retval;}function parseoverall(){ global $contents; $matches = array(); $pattern = "@<tr>\\s<td.*><a.*>\\s" . "Overall" . "\\s</a></td>\\s<td.*>([0-9,\\s]*)</td>\\s<td.*>([0-9,\\s]*)</td>\\s<td.*>([0-9,\\s]*)</td>\\s</tr>@imsU"; $match_found = preg_match($pattern, $contents, $matches); $retval = array(); if ($match_found && $matches[1] != "") $retval['rank'] = $matches[1]; else $retval['rank'] = "--"; if ($match_found && $matches[2] != "") $retval['level'] = $matches[2]; else $retval['level'] = "--"; if ($match_found && $matches[3] != "") $retval['xp'] = $matches[3]; else $retval['xp'] = "--"; return $retval;}function combat(){$info = parse("Defence");$a = $info["level"]*100;$info = parse("Hitpoints");$b = $info["level"]*100;$info = parse("Prayer");if(($info["level"]/2)!=(floor($info["level"]/2))){ $c = ($info["level"]-1)*50; }else{ $c = $info["level"]*50; }$base = ($a+$b+$c)/400;$info = parse("Attack");$d = $info["level"]*130;$info = parse("Strength");$e = $info["level"]*130;$melee = ($d+$e)/400;$info = parse("Ranged");if(($info["level"]/2)!=(floor($info["level"]/2))){ $f = (($info["level"]-1)+($info["level"]*2))*65; }else{ $f = $info["level"]*195; }$range = $f/400;$info = parse("Magic");if(($info["level"]/2)!=(floor($info["level"]/2))){ $g = (($info["level"]-1)+($info["level"]*2))*65; }else{ $g = $info["level"]*195; }$mage = $g/400;echo "<img src='http://www.runescape.com/img/kbase/menu_icons/crossed_swords_2.gif'> Combat:<br>";echo "Melee: ";echo $melee+$base;echo "<br>";echo "Range: ";echo $range+$base;echo "<br>";echo "Mage: ";echo $mage+$base;echo "<br>";}echo "Stats for: <b>".$_GET[username]."</b><br /><br />";echo "<table width='100%' cellspacing='10' cellpadding='10'>";echo "<tr>";echo "<td>";$info = parseoverall();echo "<img src='http://www.runescape.com/img/kbase/menu_icons/icon_bar_chart_2.gif'> Overall:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";combat();echo "</td>";echo "</tr>";echo "<tr>";echo "<td>";$info = parse("Attack");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_attack1.gif'> Attack:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Defence");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_defence1.gif'> Defence:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Strength");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_strength1.gif'> Strength:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "</tr>";echo "<tr>";echo "<td>";$info = parse("Hitpoints");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_hitpoints1.gif'> Hitpoints:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Ranged");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_ranged1.gif'> Ranged:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Prayer");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_prayer1.gif'> Prayer:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "</tr>";echo "<tr>";echo "<td>";$info = parse("Magic");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_magic1.gif'> Magic:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Cooking");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_cooking1.gif'> Cooking:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Woodcutting");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_woodcutting1.gif'> Woodcutting:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "</tr>";echo "<tr>";echo "<td>";$info = parse("Fletching");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_fletching1.gif'> Fletching:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Fishing");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_fishing1.gif'> Fishing:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Firemaking");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_firemaking1.gif'> Firemaking:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "</tr>";echo "<tr>";echo "<td>";$info = parse("Crafting");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_crafting1.gif'> Crafting:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Smithing");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_smithing1.gif'> Smithing:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Mining");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_mining1.gif'> Mining:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "</tr>";echo "<tr>";echo "<td>";$info = parse("Herblore");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_herblore1.gif'> Herblore:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Agility");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_agility1.gif'> Agility:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Thieving");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_thieving1.gif'> Thieving:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "</tr>";echo "<tr>";echo "<td>";$info = parse("Slayer");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_slayer1.gif'> Slayer:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Farming");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_farming1.gif'> Farming:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Runecraft");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_runecraft1.gif'> Runecraft:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "</tr>";echo "<tr>";echo "<td>";$info = parse("Hunter");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_hunter1.gif'> Hunter:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</td>";echo "<td>";$info = parse("Construction");echo "<img src='http://www.runescape.com/img/hiscores/skill_icon_construction1.gif'> Construction:<br>";if($_GET[rank]=="on"){echo "Rank: " . $info['rank'] . "<br>";}echo "Level: " . $info['level'] . "<br>";echo "XP: " . $info['xp'] . "<br>";echo "</tr>";echo "</table>";?></body></html> This is the site it's on: http://porzant.100webspace.net/index.php?Thanks for any help. Link to comment Share on other sites More sharing options...
morrisjohnny Posted July 27, 2007 Share Posted July 27, 2007 Hello i've not lucked at your code but this works fine (I use it on mine) <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title></head><body><?/* CURL FILE RETRIEVE */function return_file($filename) { $curl = curl_init(); // Initialize the CURL session curl_setopt($curl , CURLOPT_URL , $filename); // Set the URL for CURL transfer curl_setopt($curl , CURLOPT_RETURNTRANSFER , 1); // Return file as a string curl_setopt($curl , CURLOPT_VERBOSE , 1); // Output VERBOSE information, Write to STDERR curl_setopt($curl , CURLOPT_HEADER , 0); // Don't return the Header in the string $file = curl_exec($curl); // Perform the CURL session curl_close($curl); // Close the CURL session return $file;}/* RETURN ARRAY OF RECENT RUNESCAPE NEWS */function news_list($show_amount = 20) { // Limit to a list of 20 if($show_amount > 20) $show_amount = 20; // Get the Runescape News List File $file = return_file('http://news.runescape.com/lang/en/aff/runescape/list.ws'); // Extract the news rows into an array. preg_match_all('#<tr>.*?</tr>#s', $file, $matches); $matches = $matches[0]; // Create a new array for parsed news. $info = array(); // For each single news row... for($num = 1; array_key_exists($num, $matches) AND $num <= $show_amount; $num++) { $arr = array(); // Create a new array for the news information. preg_match('#<a href="newsitem.ws\?id=([0-9]*)">#', $matches[$num], $ids); // Get the news ID $arr['id'] = $ids[1]; // Add the ID to the information array. preg_match_all('#">([^<].*?)</td>#', $matches[$num], $extracted); // Extract title and date. $arr['title'] = $extracted[1][0]; // Add the TITLE to the information array. $arr['date'] = strtotime($extracted[1][1]); // Add the DATE to the information array. $info[$num] = $arr; // Add array to INFO array. } // Return the information array. return $info;}/* RETURN RUNESCAPE NEWS ARTICLE ARRAY */function news_show($id = 0) { // Get the Runescape News File $file = return_file('http://news.runescape.com/lang/en/aff/runescape/newsitem.ws?id='.$id); // Get rid of all new lines. $file = str_replace("\n", '', $file); // Extract the title, date and content. $head = preg_match("# <b>(.*?) - (.*?)</b>#s", $file, $heads); $text = preg_match('#<div style="text-align: justify;">(.*?)</div>#s', $file, $texts); // If information exists on page, add to array. $info = array(); if($head AND $text) { $info['title'] = $heads[2]; $info['date'] = strtotime($heads[1]); $info['text'] = $texts[1]; } // If information does not exist, add blank values. else { $info['title'] = ''; $info['date'] = 0; $info['text'] = ''; } // Return information array. return $info;}/* RETURN ARRAY OF RUNESCAPE STATS */function stat_arr($user = '') { $norank = '0 1 0'; $file = return_file('http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1='.$user); $data = strip_tags($file); // Rid of HTML tags $data = substr($data, strpos($data, 'Overall')); // Rid of everything before the statistics $data = substr($data, 0, strpos($data, "Search")); // Rid of everything after the statistics $data = rtrim($data, "\n "); // Cleanup end of statistics $data = preg_replace("#[\n]+?(.)#", " $1", $data); // Rid of all extra lines // If not in highscores assign defult values. if(strpos($file, 'rowspan') > 0) { $data = preg_replace("#Overall.*?Attack#", 'Overall Attack', $data); $data = str_replace(' ', ' '.$norank.' ', $data); $data .= ' '.$norank; } // If Found User else { $data = str_replace(',', '', $data); // Rid of commas $data = str_replace('Not Ranked', $norank, $data); // Replace 'Not Ranked' with zeros and ones } $data = explode(' ' , $data); // Put data into an array $stat_arr = array(); // Create new stat array. for($num = 0; isset($data[$num]); $num = $num + 4) { $tmp_arr = array(); // Create/Clear an array for the stat $tmp_arr['rank'] = $data[$num + 1]; // Add the RANK to the array $tmp_arr['level'] = $data[$num + 2]; // Add the LEVEL to the array $tmp_arr['xp'] = $data[$num + 3]; // Add the EXP to the array $stat_arr[$data[$num]] = $tmp_arr; // Add the TMP Array to the large stat array } return $stat_arr;}/* CONVERT XP TO LEVEL */function find_level($xp) { if($xp >= 13034431) return 99; $txp = 0; for($lvl = 1; floor($txp / 4) <= $xp; $lvl++) { $txp += floor($lvl + 300 * pow(2, $lvl / 7)); } return --$lvl;}/* CONVERT LEVEL TO XP */function find_xp($lvl) { $xp = 0; for(--$lvl; $lvl > 0; $lvl--) { $xp += floor($lvl + 300 * pow(2, $lvl / 7)); } $xp = floor($xp / 4); return $xp;}?><?php$whatever = stat_arr($_GET['user']);?><form><label for="user">Username:</label><input type="text" id="user" name="user" maxlength="12" size="25" /><input type="submit" value="Submit" /></form><?phpecho "Levels For <strong>".$_GET['user']."</strong><br />";// print_r with [skill] and [xp/rank/level]echo "<table cellpadding='3'><tr><td>";echo "<img src='Images/attack.png' /></td><td>";print_r($whatever[Attack][level]);echo "</td><td>";echo "<img src='Images/hitpoints.png' /></td><td>";print_r($whatever[Hitpoints][level]);echo "</td><td>";echo "<img src='Images/mining.png' /></td><td>";print_r($whatever[Mining][level]);echo "</td></tr><tr><td>";echo "<img src='Images/strength.png' /></td><td>";print_r($whatever[strength][level]);echo "</td><td>";echo "<img src='Images/agility.png' /></td><td>";print_r($whatever[Agility][level]);echo "</td><td>";echo "<a href='Smelting.php?user=".$_GET['user']."' border='0'><img src='Images/smithing.png' /></a></td><td>";print_r($whatever[smithing][level]);echo "</td></tr><tr><td>";echo "<img src='Images/defence.png' /></td><td>";print_r($whatever[Defence][level]);echo "</td><td>";echo "<img src='Images/herblore.png' /></td><td>";print_r($whatever[Herblore][level]);echo "</td><td>";echo "<img src='Images/fishing.png' /></td><td>";print_r($whatever[Fishing][level]);echo "</td></tr><tr><td>";echo "<img src='Images/ranged.png' /></td><td>";print_r($whatever[Ranged][level]);echo "</td><td>";echo "<img src='Images/thieving.png' /></td><td>";print_r($whatever[Thieving][level]);echo "</td><td>";echo "<img src='Images/cooking.png' /></td><td>";print_r($whatever[Cooking][level]);echo "</td></tr><tr><td>";echo "<img src='Images/prayer.png' /></td><td>";print_r($whatever[Prayer][level]);echo "</td><td>";echo "<img src='Images/crafting.png' /></td><td>";print_r($whatever[Crafting][level]);echo "</td><td>";echo "<img src='Images/firemaking.png' /></td><td>";print_r($whatever[Firemaking][level]);echo "</td></tr><tr><td>";echo "<img src='Images/magic.png' /></td><td>";print_r($whatever[Magic][level]);echo "</td><td>";echo "<img src='Images/fletching.png' /></td><td>";print_r($whatever[Fletching][level]);echo "</td><td>";echo "<img src='Images/woodcutting.png' /></td><td>";print_r($whatever[Woodcutting][level]);echo "</td></tr><tr><td>";echo "<img src='Images/runecraft.png' /></td><td>";print_r($whatever[Runecraft][level]);echo "</td><td>";echo "<img src='Images/slayer.png' /></td><td>";print_r($whatever[slayer][level]);echo "</td><td>";echo "<img src='Images/farming.png' /></td><td>";print_r($whatever[Farming][level]);echo "</td></tr><tr><td>";echo "<a href='Construction.php?user=".$_GET['user']."' border='0'><img src='Images/construction.png' /></td><td>";print_r($whatever[Construction][level]);echo "</td><td>";echo "<img src='Images/hunter.png' /></td><td>";print_r($whatever[Hunter][level]);echo "</td><td>";echo "<img src='Images/overall.png' /></td><td>";print_r($whatever[Overall][level]);echo "</td></tr></table>";?></body></html> Link to comment Share on other sites More sharing options...
justsomeguy Posted July 27, 2007 Share Posted July 27, 2007 Add this to the top of the page:ini_set("display_errors", 1);error_reporting(E_ALL); Link to comment Share on other sites More sharing options...
magic24688 Posted July 27, 2007 Share Posted July 27, 2007 I'm going to make a quick suggestion. With a new RS update getting the user's information is alot easyier now.Useing this link below you can get the users information. This should make the patterns mutch easyer.http://hiscore.runescape.com/index_lite.ws...er=YourUsernameMore information how it's used and which is which please read HEREThis can possible help you or you can use the highscore it's self. Just a quick suggestion. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.