this will retrieve your halo 3 weapon kills and medals from social rankings. the image id and how many kills/medals gets spit out via array ( example of how to use image id within snippet ).
made this for a facebook app that im creating and decided to share. this snippet is not mysql reliant, it stores everything within the specified cache file ('xbl_h3_cache.txt').
Usage: xbl_h3.php?gt=
demo: http://seantristin.com/testlab/xbl/xbl_h3.php?gt=sT%20threeZ
<pre>
<?php
$cache_file = 'xbl_h3_cache.txt';
$cache = ( file_exists($cache_file) ? unserialize(file_get_contents($cache_file)) : array() );
print("\n\nRecent Gamertags looked up:\n ");
foreach ( $cache as $gt => $a )
printf(' <a href="xbl_h3.php?gt=%s">%s</a> (%ss ago) ', $gt, $gt, time() - $a[0]);
if ( !isset($_GET['gt']) )
die('no gt');
if ( !strlen($_GET['gt']) )
die('no gt');
if ( !isset($cache[$_GET['gt']]) )
{
$cache[$_GET['gt']] = array(0, NULL);
}
if ( $cache[$_GET['gt']][0] < (time() - 99) )
{
$start = microtime(true);
$c = curl_init();
curl_setopt($c, CURLOPT_URL, 'http://www.bungie.net/stats/halo3/CareerStats.aspx?player=' . urlencode($_GET['gt']) . '&social=true&map=0');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9) Gecko/2008062315 (Gentoo) Firefox/3.0.1');
$o = curl_exec($c);
//$o = @iconv('UTF-8', 'ISO-8859-1', $o);
if ( ($ea = curl_errno($c) || $eb = curl_error($c)) )
die("error 0x00");
curl_close($c);
$took = round(microtime(true) - $start, 2);
print("\n\n[ ] Cache (0s old) [×] Bungie (took {$took}s)\n\n");
//file_put_contents('xbl_h3_o.txt', $o);
$e = '/\<div .*\>[.\r\n\t ]*\<div .*\>\<img .* src\="\/images\/halo3stats\/weapons\/(.*)\.gif" .* \/\>\<\/div\>[.\r\n\t ]*\<div .*\>\<div .*\>(.*)\<\/div\>\<div .*\>(.*)\<\/div\>\<\/div\>[.\r\n\t ]*\<div .*\>\<div .*\>Total Kills\<\/div\>\<div .*\>(.*)\<\/div\>\<\/div\>[.\r\n\t ]*\<\/div\>/';
if ( !preg_match_all($e, $o, $m) )
die("error 0x01");
unset($m[0]);
$x = count($m[1]);
for ( $i = 0; $i < $x; $i++ )
{
$guns[$m[2][$i]] = array('ImageId' => $m[1][$i], 'Kills' => $m[4][$i]);
//print("<img src='http://www.bungie.net/images/halo3stats/weapons/{$m[1][$i]}.gif' />");
}
$e = '/\<div .*\>[.\r\n\t ]*\<div .*\>\<img .* src="\/images\/halo3stats\/medals\/(.*).gif" .* \/\>\<\/div\>[.\r\n\t ]*\<div .*\>\<div .*\>(.*)\<\/div\>\<div .*\>(.*)\<\/div\>\<\/div\>[.\r\n\t ]*\<div .*\>\<div .*\>Game Total\<\/div\>\<div .*\>(.*)\<\/div\>\<\/div\>[.\r\n\t ]*\<\/div\>/';
if ( !preg_match_all($e, $o, $m) )
die("error 0x02");
unset($m[0]);
$x = count($m[1]);
for ( $i = 0; $i < $x; $i++ )
{
$medals[$m[2][$i]] = array('ImageId' => $m[1][$i], 'MedalCount' => $m[4][$i]);
//print("<img src='http://www.bungie.net/images/halo3stats/medals/{$m[1][$i]}.gif' />");
}
$cache[$_GET['gt']] = array(time(), $guns, $medals);
file_put_contents($cache_file, serialize($cache));
}
else
{
$guns = $cache[$_GET['gt']][1];
$medals = $cache[$_GET['gt']][2];
$cache_age = time() - $cache[$_GET['gt']][0];
print("\n\n[×] Cache ({$cache_age}s old) [ ] Bungie (took 0s)\n\n");
}
print_r($guns);
print_r($medals);
?>
</pre>
<style type="text/css">
* { margin: 0; padding: 0; }
</style>