getSource(); $RS->parseArray(); $stats = $RS->getResult(); echo << SkillRankLevelXP HTML; foreach($stats as $values){ echo "\n"; echo ''.$values['skill'].''; echo ''.$values['rank'].''; echo ''.$values['level'].''; echo ''.$values['xp']."\n"; echo "\n"; } echo ''; */ class RuneScapeStats { /** * Het domein van de runescape server * * @access public * @var string */ var $server = 'hiscore-web.runescape.com'; /** * De relatieve url om bij het juiste bestand * op de server te komen * * @access public * @var string */ var $relURL = 'lang/en/aff/runescape/hiscorepersonal.ws'; /** * Gebruikersnaam van de speler waarvan de stats * opgevraagt moeten worden * * @access public * @var string */ var $user; /** * Dit is de variabele waar de verkregen data uiteindelijk * in wordt gezet * * @access public * @var array */ var $statsArray; /** * De skills waar een waarde bij gezocht moet worden * * @access public * @var array */ var $disciplines = 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'); /** * true als je debugmessages wilt weergeven, false zo niet *e * @var bool */ var $debug = false; var $_httpBody = ""; var $_source; /** * Constructor method; url-codeert de spelers naam * waarvan de stat opgezocht moeten worden * * @param string $user * @return void * @access public */ function RunescapeStats($user){ $this->user = urlencode($user); } /** * Haal de benodigde data van de server in html formaat * * @return bool * @static false * @access public */ function getSource() { $this->addParam('user1', $this->user); $this->addParam('submit', 'Search'); $fp = fsockopen($this->server, 80, $errno, $errstr, 10); if(!$fp){ return false; } $contentLen = strlen($this->_httpBody); $req = <<relURL} HTTP/1.1 Host: {$this->server} Referer: http://{$this->server}/{$this->relURL} Connection: Keep-Alive Content-Type: application/x-www-form-urlencoded Content-Length: {$contentLen} {$this->_httpBody} REQUEST; fwrite($fp, $req); $stop = false; while (!$stop && !feof($fp)) { $fetch = fgets($fp, 128); $this->_source.= $fetch; if(strstr($fetch, 'This webpage') !== false){ fwrite($fp, "Connection: close\r\n\r\n"); fclose($fp); $stop = true; } } return true; } /** * Zet alle stats in een array * * @static false * @access public * @return void */ function parseArray() { if (strstr($this->_source, "does not feature in the hiscores")) { $this->statsArray = false; return; } $i = 1; foreach ($this->disciplines as $type) { //echo str_replace("\n", "", $this->_source); if( eregi($type . '([0-9\,]+)([0-9]+)([0-9\,]+)', str_replace("\n", "", $this->_source), $regs) ){ // De structuur van de array wordt hier gemaakt, en kun je hier dus ook aanpassen $this->statsArray[$i]['skill'] = $type; $this->statsArray[$i]['rank'] = $regs[1]; $this->statsArray[$i]['level'] = $regs[2]; $this->statsArray[$i]['xp'] = $regs[3]; } else { $this->statsArray[$i]['skill'] = $type; $this->statsArray[$i]['rank'] = 0; $this->statsArray[$i]['level'] = 0; $this->statsArray[$i]['xp'] = 0; } $i++; } } /** * Voeg een parameter toe aan de body * * @param string $name * @param string $value * @return void * @static false * @access public */ function addParam($name, $value) { strlen($this->_httpBody)<1 ? $this->_httpBody=$name.'='.$value : $this->_httpBody.='&'.$name.'='.$value ; } /** * Spuug de gevormde array uit * * @return array */ function getResult() { return $this->statsArray; } function execute() { if ( $this->getSource() ) { $this->parseArray(); } else { $this->debug?trigger_error("Fout bij het ophalen van de source"):null; $this->statsArray = false; } } } // Voorbeeldje, dit is de meest saaie toepassing van het script echo '
'; echo 'Naam:   '; echo '
'; echo '

'; if(isset($_GET['naam'])){ $RS = new RuneScapeStats($_GET['naam']); $RS->execute(); $stats = $RS->getResult(); if ($stats != false) // Als de naam niet in de hiscores voorkomt zal $stats false zijn, ander is $stats een array { echo << SkillRankLevelXP HTML; foreach($stats as $values){ echo "\n"; echo ''.$values['skill'].''; echo ''.$values['rank'].''; echo ''.$values['level'].''; echo ''.$values['xp']."\n"; echo "\n"; } echo ''; } else { echo "Naam niet gevonden in de hiscores"; } // var_dump($stats); unescape om de structuur van de array te zien } ?>