quote:
Originally posted by Guillaume
code:
<?
$handle = fopen("http://www.bungie.net/Stats/PlayerStats.aspx?player=guyguyme2003", "rb");
$contents = '';
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
fclose($handle);
$match = InsideTags('<div class="ExpBar" style="width:50"><div class="ExpBarText" style="left:20">','</div></div>',$contents); // uses a regular expression and gets the stuff inbetween those two points and returns it
$rumble_pit = $match[1][0];
$team_skirmish = $match[1][1];
$head_to_head = $match[1][2];
$big_team_battle = $match[1][3];
$team_slayer = $match[1][4];
function InsideTags($tag1,$tag2,$html){ //function to grab text inbetween two points
$tag2 = str_replace('/', "\/" ,$tag2);
preg_match_all("/$tag1(.*)$tag2/i", $html, $match);
return $match;
}
header("Content-type: image/png");
$im = @imagecreatefromjpeg("http://guillaumelforum.theglassprison.net/halo2/Halo%202%20Stats_files/statsforimg.jpg");
$text_color = imagecolorallocate($im, 255, 255, 255);
$line = 42;
imagestring($im, 1, 102, $line, $rumble_pit, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $team_skirmish, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $head_to_head, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $big_team_battle, $text_color);
$line = $line + 10;
imagestring($im, 1, 102, $line, $team_slayer, $text_color);
imagepng($im);
imagedestroy($im);
?>
err is that still how to script works? is there no caching? you know everytime that script is loaded it downloads the whole stats page ?
you need to set up a caching system how i would do it is check if the cache exists then if it does i would check the current time (time() ) agiesnt the file time of the cache file ( filemtime($cache) )
if the cache is past 30min or so (the time() produces funky unix time use something like $blah = time() - filemtime($cache); to get seconds scince last update )
then if its like 30min past last update download the stats again and write it to a file (use fwrite) .
If its not 30min past use fread to read the cache file then load it into your script and use that for stats insted.
post if you dont quite get me and ill post some sample code
but look up some of the terms i used like fwrite and search it on
http://php.net
but atleast try to make some of the code
or post here for help