/    Sign up×
Community /Pin to ProfileBookmark

Pulling dynamically changing information from a game site

I would like to pull certain information from a game onto my website. (I hope “pull” is the correct word.) Player rank information for this game can be seen [URL=http://www.kingsofchaos.com/battlefield.php?start=0]here[/URL]. For example, with [URL=http://www.kingsofchaos.com/stats.php?id=1683506]this[/URL] person – at this very moment, one of the user stats of MidnightRain is “[b]Army Size: 1,423,073[/b]
I would like to pull this number, which constantly changes, onto my site.

Essentially, in the end, i would like my site to displays, certain information about particular users, in a list.

Eg.
Army size of X = 455,959
Army size of Y = 50,595
Army size of Z = 59,599,394

I hope this makes sense, and thank you for any help ?

Shears ?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 06.2006 — This will load all the info from that table into an array, from which you can then extract whatever data you want to display. Just copy-and-paste it into a .php file and run it, and you'll see how the data is stored in the $data array.
[code=php]
<?php
$html = file_get_contents("http://www.kingsofchaos.com/battlefield.php?start=0");
if($html !== FALSE)
{
$s = '[srn]*'; // whitespace/new line
$regex = '|<tr[^>]*>'.$s.'<td><a[^>]*>([^<]*)</a></td>'.
''.$s.'<td[^>]*>([^<]*)</td>'.$s.'<td[^>]*>'.$s.'([^<]*)'.$s.'</td>'.
''.$s.'<td[^>]*>([^<]*)</td>'.$s.
'<td[^>]*>([^<]*)</td>'.$s.'</tr>|Us';
preg_match_all($regex, $html, $matches);
$items = array(1 => 'name',
2 => 'army',
3 => 'race',
4 => 'gold',
5 => 'rank');
for($ix = 0; $ix < count($matches[1]); $ix++)
{
foreach($items as $key => $cat)
{
$data[$ix][$cat] = trim($matches[$key][$ix]);
}
}
// show data:
echo "<pre>";
print_r($data);
echo "</pre>n";
}
?>
[/code]
Copy linkTweet thisAlerts:
@ShearsauthorJul 07.2006 — Thank you NogDog! That was just what i wanted ?

[code=php] $regex = '|<tr[^>]*>'.$s.'<td><a[^>]*>([^<]*)</a></td>'.
''.$s.'<td[^>]*>([^<]*)</td>'.$s.'<td[^>]*>'.$s.'([^<]*)'.$s.'</td>'.
''.$s.'<td[^>]*>([^<]*)</td>'.$s.
'<td[^>]*>([^<]*)</td>'.$s.'</tr>|Us';[/code]
I have one question. What is the significance of writing [b]Us[/b] at the end of the $regex ?

Thank you again ?

Shears ?
Copy linkTweet thisAlerts:
@NogDogJul 07.2006 — U = toggles to Ungreedy mode, so that the shortest part of the string that matches is selected instead of the longest

s = Doesn't seem to actually stand for anything, but the purpose is to have the "." wildcard character match newlines as well as any other character (by default it does not match newlines)

More info at: http://www.php.net/manual/en/reference.pcre.pattern.modifiers.php
×

Success!

Help @Shears spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...