Jockiboi
Banned User
- Joined
- Oct 12, 2010
- Messages
- 1,156
- Reaction score
- 9
Hiho!
I've now been trying to make a scrapper for online list @ Tibia.com. My code so far looks liek:
resulT= 'null'
helps pls
I've now been trying to make a scrapper for online list @ Tibia.com. My code so far looks liek:
PHP:
<?php
error_reporting(E_ALL ^ E_NOTICE);
class tibia {
private $_worldURL = 'http://www.tibia.com/community/?subtopic=worlds&world=%s';
public function getPlayerOnlineStatus( $world ) {
$url = sprintf($this->_worldURL, ucfirst($world));
$raw = file_get_contents($url);
$data = null;
if(strpos($raw, 'Players Online') > 0) {
$data = array();
$raw = str_replace(array('<br />', ' '), array('', ' '), $raw);
$raw = preg_replace('/<A HREF="([^>]+)">([^<]+)<\/A>/', '[url=\1]\2[/url]', $raw);
preg_match_all('/>(Name|Level|Vocation):(?:<\/?[^>]+>){2}([^<]+)/', $raw, $matches);
for($i = 0, $count = count($matches[0]); $i < $count; $i++) {
$var = str_replace(' ', '_', strtolower($matches[1][$i]));
$value = html_entity_decode(trim($matches[2][$i])); //Trim so you wont be needing to remove spaces and save more "clean" strings
$data[$var] = $value;
}
}
return $data;
}
}
$tibia = new tibia;
$tibia->getPlayerOnlineStatus('Nova');
if ($data != NULL) {
echo $data['name'];
} else { echo 'null'; }
?>
resulT= 'null'
helps pls