 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
01-22-2008, 07:45 AM
|
#1 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
A form of a image class..
Hey!
I'm having a problem..
I wanna code a class, that would let me do something like this:
php Code:
$image = new TibiaChar ('Mortis Dominus'); if($image) { echo $image-> getImageCode(); }else { echo 'Character does not exist!'; }
And that would search Tibia - Free Multiplayer Online Role Playing Game - News character page for Mortis Dominus, and if it exists, it would do some fetching of the data on that character page, and create an image for it.
Character page is: Tibia - Free Multiplayer Online Role Playing Game - Community
Then it would echo out a image code, such as "www.domain.com/images/mortis_dominus.png" so I can use it as a dynamic image.
How would I achieve this?
I know I have to use file_get_contents, and also use the PHP GD library..
I have an example here:
Tibia - Character Image
|
|
|
|
01-22-2008, 09:46 AM
|
#2 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
do we have a form of api for this? ie how do you get the data for the character?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
01-22-2008, 11:16 AM
|
#3 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
with file_get_contents and using preg_match on the resulted page IF the character existed.
Tibia - Free Multiplayer Online Role Playing Game - Community
As you see on the link, if you click it, you come to the page with the data of my char.. if you write a char that doesn't exist instead of "Mortis%20Dominus", you won't get that page..
|
|
|
|
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.
|
|
|
|
The Following User Says Thank You to Wildhoney For This Useful Post:
|
|
01-22-2008, 02:58 PM
|
#5 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
PHP Code:
for($iIndex = 0; $iIndex < count($aMatches[1]); $iIndex++)
NOOOOOOOOOOOOOOOOOoooooooooooooooooOOOOOOOOOOOOOoo ooo
PHP Code:
$iNumMatches = count($aMatches[1]); for($iIndex = 0; $iIndex < $iNumMatches; $iIndex++)
being picky abit there, im just allergic to count() being used there.
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
|
The Following User Says Thank You to sketchMedia For This Useful Post:
|
|
01-22-2008, 03:13 PM
|
#6 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by sketchMedia
PHP Code:
for($iIndex = 0; $iIndex < count($aMatches[1]); $iIndex++)
NOOOOOOOOOOOOOOOOOoooooooooooooooooOOOOOOOOOOOOOoo ooo
PHP Code:
$iNumMatches = count($aMatches[1]); for($iIndex = 0; $iIndex < $iNumMatches; $iIndex++)
being picky abit there, im just allergic to count() being used there.
|
You should be because putting it in the for loop executed count each time.
|
|
|
|
01-22-2008, 03:12 PM
|
#7 (permalink)
|
|
The Acquainted
Join Date: Nov 2007
Location: Netherlands
Posts: 113
Thanks: 11
|
lol @ sketchmedia
You can even do it in one line:
PHP Code:
for($iIndex = 0, $iNumMatches = count($aMatches[1]); $iIndex < $iNumMatches; $iIndex++)
For another speed boost you should use curl instead of file_get_contents
|
|
|
|
01-22-2008, 03:26 PM
|
#8 (permalink)
|
|
The Prestige
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
|
which was precisely why i objected to it in the first place
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
|
|
|
|
01-22-2008, 06:12 PM
|
#9 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Thanks!!!
I got a question though about your code there..
I suck at those.. preg_replace and that..
And I know I should read about it in some tutorial.. but I just don't.. understand it :(
So could someone please explain this to me:
PHP Code:
preg_match_all('~<td[\swidth=20%]*>([^<]+):</td><td>([^<]+)</td>~i', $szContent, $aMatches);
Also, how would I make an image out of it?
If you go to this site:
Tibia - Character Image
And enter "Mortis Dominus" as character.. you'll get an image.
Also, that image is updated every 10 minutes, how would I achieve that?
Thanks alot!
|
|
|
|
01-23-2008, 07:21 PM
|
#11 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Anyone? xD
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Hybrid Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|