PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
toms100
Forum Contributor
Posts: 119 Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK
Post
by toms100 » Sun Apr 27, 2003 3:39 pm
ok here is my script working:
http://www.saundersbc.f2s.com/stat.php?UN=gurlen_borg
you can change UN to any runescape username (if you know what that is)
anyway
when it generates the image it does the text on different lines for some reason!
here is my image code:
Code: Select all
<?php
function drawStat($rank,$xp, $x = 300, $y = 30) {
header("Content-type: image/png");
$image = imagecreate($x,$y);
$fontsize = 12;
$font = "/web/sites/296/saundersbc/www.saundersbc.f2s.com/font.ttf";
$blue = imagecolorallocate($image, 0,0,255);
$white = imagecolorallocate($image, 255,255,255);
imagefill($image, 0, 199, $white);
$text = "Rank: $rank TotalXP: $xp";
imageTTFtext( $image, $fontsize, 0,2,18, $blue, $font, $text);
imagejpeg($image);
}
?>
i hope someone can help
this is driving me mad
[]InTeR[]
Forum Regular
Posts: 416 Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands
Post
by []InTeR[] » Sun Apr 27, 2003 5:17 pm
Maybe there are some \n's or \r's in the vars?
toms100
Forum Contributor
Posts: 119 Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK
Post
by toms100 » Mon Apr 28, 2003 2:57 am
yes i think your right, if i put in the values by typing it comes out fine..
well heres the rest of my script which must be causing the problem
Code: Select all
<?php
function getstats($username) {
$webpage = "http://www.runescape.com/hiscoreuser.cgi?category=0&username=".$username;
$fp = fopen( $webpage, "r" ) or die("couldnt open $webpage");
$page = explode(' ', implode('', file($webpage)) ); // split it into words
$word = count($page);
$i = 0;
while ($i <= $word) {
$temp = str_replace( '<', '.', $page[$i] );
$temp = str_replace( '>', '.', $temp );
$temp = str_replace( ' ', '', $temp );
$pg = explode('.',$temp);
$o = 0;
$todo = count($pg);
while ( $o <= $todo ) {
if ( $pg[$o] == "color=yellow" ) {
/// i know the next value will be rank
if (isset($s)){
$xp = str_replace('\r', '',$pg[$o+1] );
$xp = str_replace('\n', '',$xp );
print "$xp<br>";
}
else {
$rank = str_replace('\r', '',$pg[$o+1] );
$rank = str_replace('\n', '',$rank );
print "$rank<br>";
$s = 1;
}
/// etc..
}
$o++;
}
$i++;
}
$GLOBALS['rank'] = $rank;
$GLOBALS['xp'] = $xp;
}
?>
[]InTeR[]
Forum Regular
Posts: 416 Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands
Post
by []InTeR[] » Mon Apr 28, 2003 3:16 am
Can you parse
var_dump($text);
Just before imageTTFtext.
Then you can see if you have some enters in it.
toms100
Forum Contributor
Posts: 119 Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK
Post
by toms100 » Mon Apr 28, 2003 4:04 am
i did the var_dump
and $xp ends up as
їcode]
string(8) " 4863750"
and $rank ends up as:
string(5) " 5323"
ї/code]
toms100
Forum Contributor
Posts: 119 Joined: Wed Feb 26, 2003 10:29 am
Location: Bristol,UK
Post
by toms100 » Mon Apr 28, 2003 4:06 am
YAY I GOT IT TO WORK:)
i noticed there was whitespace at the begging so i trimed the variables and it worked!!!!
thanks for the suggestions:)