Jump to content

Hiscore help


rswildy

Recommended Posts

Hi, Now if i change the name of the skill it won't work because its getting the source from runescape.com so if i wanted to make say the "Attack" go to a page called attack.php or wanted to change the font to red / bold or something how could that be done, If you altar the name on the $skill_list it wont work you will just get an extra tab onto the hiscore list. For example if you put <b> </b> tags on Overall then it will show up twice on the hiscore list the bold version will just say -- and wont retrieve any details the normal version will apear as normal (unedited).

<?phpif (isset($_GET['name'])){  $skill_list = 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");  $contents = "";  $handle = fopen("http://hiscore.runescape.com/lang/en/aff/runescape/hiscorepersonal.ws?user1=".urlencode($_GET['name']),"r");  if($handle)  {	while (!feof($handle))	{	  $contents .= fread($handle, 8192);	}	fclose($handle);  }  echo "<table cellpadding=\"0\" cellspacing=\"0\">";  echo "<tr>";  echo "<td style=\"border-bottom: 1px solid black;\">Skill</td>";  echo "<td style=\"border-bottom: 1px solid black;\">Rank</td>";  echo "<td style=\"border-bottom: 1px solid black;\">Level</td>";  echo "<td style=\"border-bottom: 1px solid black;\">XP</td>";  echo "</tr>";  $bg = false;  $found_skills = array();  $skills = parse($contents);  foreach ($skills as $info)  {	if ($bg)	  echo "<tr style=\"background: #333333;\">";	else	  echo "<tr>";	echo "<td>{$info['skill']}</td>";	echo "<td>{$info['rank']}</td>";	echo "<td>{$info['level']}</td>";	echo "<td>{$info['xp']}</td>";	echo "</tr>";	$found_skills[] = $info['skill'];	$bg = !$bg;  }  $missing_skills = array_diff($skill_list, $found_skills);  foreach($missing_skills as $skill)  {	if ($bg)	  echo "<tr style=\"background: #333333;\">";	else	  echo "<tr>";	echo "<td>{$skill}</td>";	echo "<td>--</td>";	echo "<td>--</td>";	echo "<td>--</td>";	echo "</tr>";	$bg = !$bg;  }  echo "</table>";}function parse($contents){  $matches = array();  $pattern = "@<tr>\\s<td.*><a.*>\\s([^<]+)\\s</a></td>\\s<td.*>([0-9,\\s]*)</td>\\s<td.*>([0-9,\\s]*)</td>\\s<td.*>([0-9,\\s]*)</td>\\s</tr>@imsU";  $nr_matches = preg_match_all($pattern, $contents, $matches);  $retval = array();  $i = 0;  for ($i = 0; $i < count($matches[1]); $i++)  {	$retval[$i]['skill'] = $matches[1][$i];	$retval[$i]['rank'] = $matches[2][$i];	$retval[$i]['level'] = $matches[3][$i];	$retval[$i]['xp'] = $matches[4][$i];  }  return $retval;}?>

Thanks, Rswildy.

Link to comment
Share on other sites

I'm not sure on what you mean the problem is, but if you want to remove tags from the values you can strip the tags like this:

echo "<tr>";	echo "<td>" . preg_replace( '/<(.*)>/', '', $info['skill'] ) . "</td>";	echo "<td>" . preg_replace( '/<(.*)>/', '', $info['rank'] ) . "</td>";	echo "<td>" . preg_replace( '/<(.*)>/', '', $info['level'] ) . "</td>";	echo "<td>" . preg_replace( '/<(.*)>/', '', $info['xp'] ) . "</td>";	echo "</tr>";

Link to comment
Share on other sites

rofl, runescape. just ask micheal west, i have him on my msn, he made runehead. u can find him on RSD forums, but good luck with it. cause every1 uses runehead

Link to comment
Share on other sites

The skill list is not for displaying anything, it's for reading the data from the runescape site. If you change that, obviously it's going to be looking for different things from the runescape site, and that's not what you want, you just want to change how it looks. So change the output part, if you want it red and bold:

foreach ($skills as $info)  {	if ($bg)	  echo "<tr style=\"background: #333333;\">";	else	  echo "<tr>";	echo "<td><div style=\"font-weight: bold; color: red;\">{$info['skill']}</div></td>";	echo "<td>{$info['rank']}</td>";	echo "<td>{$info['level']}</td>";	echo "<td>{$info['xp']}</td>";	echo "</tr>";	$found_skills[] = $info['skill'];	$bg = !$bg;  }

Link to comment
Share on other sites

This may sound a little complex, but you will want to either set up more arrays to hold the extended information for each skill, or create an object for each skill. So, the $skill_list array would need to be something like this:

$skill_list = array(  "Overall" => array("color" => "#FF0000", "link" => "overall.php"),  "Attack" => array("color" => "#CC0000", "link" => "attack.php"),  ...);

In that case, you would also have to change this:

$missing_skills = array_diff($skill_list, $found_skills);

to this:

$missing_skills = array_diff(array_keys($skill_list), $found_skills);

And then the display loop can use the extra information:

foreach ($skills as $info)  {	if ($bg)	  echo "<tr style=\"background: #333333;\">";	else	  echo "<tr>";	echo "<td><div style=\"font-weight: bold; color: " . $skill_list[$info['skill']]['color'] . ";\"><a href=\"" . $skill_list[$info['skill']]['link'] . "\">{$info['skill']}</a></div></td>";	echo "<td>{$info['rank']}</td>";	echo "<td>{$info['level']}</td>";	echo "<td>{$info['xp']}</td>";	echo "</tr>";	$found_skills[] = $info['skill'];	$bg = !$bg;  }

Link to comment
Share on other sites

that all works fine but when skill is found it will show link however if its not found(they aren't ranked), It wont show link. I want it to show link no matter what, How could i do that?EDIT: Oh haha it does, My bad it was an error i made.

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
×
×
  • Create New...