How does the highscore lookup in your calculators work?
I'm creating one for a browser-based world switcher currently in the works (
http://world-switcher.atspace.com), but it uses a screen scraper in PHP. This seems innefficent and terribly prone to breaking.
Is there a better way?
My code is listed below...
Code:
function screenScrapeRunescape($user_name) {
$query="http://hiscore-web.runescape.com/aff/runescape/hiscorepersonal.cgi?username=".$user_name;
$result=file($query);
$one_liner="";
if(sizeof($result)!=0) {
foreach($result as $val) {
$one_liner.=$val;
}
}
$one_liner=preg_replace("/(<style.*\/style>)|(<script.*\/script>)/i","",$one_liner);
$stripped_result=htmlentities(strip_tags($one_liner));
$stripped_result=preg_replace("/login(.|\s)*$/i","",$stripped_result);
$stripped_result=preg_replace("/^(.|\s)*xp(\s)*/i","",$stripped_result);
$stripped_result=preg_replace("/(\n){1,10}/i","\n",$stripped_result);
$stripped_result=preg_replace("/\&.*;/i","",$stripped_result);
$stripped_result=preg_replace("/^\s+/","",$stripped_result);
$stripped_result=preg_replace("/\s+$/","",$stripped_result);
$stripped_result=preg_replace("/\n/","<br />\n",$stripped_result);
$stripped_result=preg_replace("/<br \/>\n<br \/>/","",$stripped_result);
$stripped_result=preg_replace("/(((Attack)|(Defence)|(Strength)|(Hitpoints)|(Overall)|(Ranged)|(Prayer)|(Magic)|(Cooking)|(Woodcutting)|(Fletching)|(Fishing)|(Firemaking)|(Crafting)|(Smithing)|(Mining)|(Herblore)|(Agility)|(Thieving)|(Slayer)|(Farming)|(Runecrafting))<br \/>\n((\d+(\,)?)*)<br \/>\n((\d+(\,)?)*)<br \/>\n((\d+\,?)*))/i","\n<div style=\"border:solid black 1px;background-color:#f0f0f0;margin:2px;padding:5px;\">\n<strong>$2</strong><br />\n<em>Rank</em>: $25<br />\n<em>Level</em>: $28<br />\n<em>Experience</em>: $31\n</div>\n",$stripped_result);
return $stripped_result;
}