01-22-2008, 01:24 PM
|
#4 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
|
Wrote you a class for this because I'm feeling kind today  ! Don't forget to mention TalkPHP wherever!
php Code:
<?php class TalkPHP_TibiaChar { private $m_aData; private $m_bFound; const TIBIA_ADDRESS = 'http://www.tibia.com/community/?subtopic=characters&name=%s'; public function find ($szCharacter) { $szCharacter = urlencode($szCharacter); $szContent = file_get_contents(sprintf(self:: TIBIA_ADDRESS, $szCharacter)); if(empty($szContent)) { throw new Exception ('Tibia content is not available'); } preg_match_all('~<td[\swidth=20%]*>([^<]+):</td><td>([^<]+)</td>~i', $szContent, $aMatches); for($iIndex = 0; $iIndex < count($aMatches[ 1] ); $iIndex++ ) { $szKey = preg_replace('~[^a-z]+~i', '', ucwords($aMatches[ 1][ $iIndex] )); $szValue = ucwords(html_entity_decode($aMatches[ 2][ $iIndex] )); $this-> m_aData[ $szKey] = $szValue; } } public function __call($szCall, $aArgs) { if(preg_match('~get(?P<key>.+)~i', $szCall, $aMatches)) { if(! array_key_exists($aMatches[ 'key'], $this-> m_aData)) { return false; } return $this-> m_aData[ $aMatches[ 'key']]; } } public function isCharacter () { if(count($this-> m_aData) > 0) { return true; } return false; } } $pTibia = new TalkPHP_TibiaChar (); $pTibia-> find('Mortis Dominus'); if($pTibia-> isCharacter()) { echo 'Name: ' . $pTibia-> getName(); echo '<br />'; echo 'Sex: ' . $pTibia-> getSex(); echo '<br />'; echo 'Profession: ' . $pTibia-> getProfession(); echo '<br />'; echo 'Level: ' . $pTibia-> getLevel(); echo '<br />'; echo 'World: ' . $pTibia-> getWorld(); echo '<br />'; echo 'Residence: ' . $pTibia-> getResidence(); echo '<br />'; echo 'Last Login: ' . $pTibia-> getLastLogin(); echo '<br />'; echo 'Account Status: ' . $pTibia-> getAccountStatus(); } else { die('Character does not exist.'); }?>
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|