mrbuter Posted June 21, 2008 Share Posted June 21, 2008 Hi again! I'm making what I thought would be (and probably is but I'm not able to do it ) a simple forum signature for someone using imagettftext in php. It's a shoutbox type thing where people can go to a webpage and enter their nick and comment and it'll add it into a database. Then I have the image.php file connect to the database and read the stuff from there. But alas I have a problem! see here: it works like so $text1 = blablabla $text2 = blablabla2 (etc.) then: imagettftext($im, 10, 0, 150, 70, $black, $font, $text); imagettftext($im, 10, 0, 40, 110, $black, $font, $text2); I have text1 set to a nondynamic thing so that works fine. I made $text2 into: $text2 = for($x=0;$x<$nbr_rangees;$x++){ "" . mysql_result($results_text,$x,"nick") . ": " . mysql_result($results_text,$x,"comment") . "\n"; } And I get.. Parse error: syntax error, unexpected T_FOR in /.../image.php on line 39 so what gives? I guess you cant use a for loop there? But then what can I use to get the same results? Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/ Share on other sites More sharing options...
mrbuter Posted June 21, 2008 Author Share Posted June 21, 2008 I suppose I could put the $text2 IN the for loop but that gets more complicated right? Because I can't have multiple $text2s. It would have to increment into like $text2 $text3 $text4 depending how many lines there are/fit. But I don't know how to do that Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/#findComment-571140 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 Make an array inside the for loop. You can't use a for loop in the current way you have it. And I'd personally cache the images after you make them so your server doesn't explode (not really "explode"...but it'll load kind of slowly when calling images). Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/#findComment-571142 Share on other sites More sharing options...
mrbuter Posted June 21, 2008 Author Share Posted June 21, 2008 make an array inside the for loop. Never done this before. Something like this? for($x=0;$x<$nbr_rangees;$x++){ $text["2"+i] = "" . mysql_result($results_text,$x,"nick") . ": " . mysql_result($results_text,$x,"comment") . "\n"; } But then I'd also need to put the imagettftext($im, 10, 0, 40, 110, $black, $font, $text2); line into a loop as well right? I'm sure I just completely butchered what an array in a for loop even is. Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/#findComment-571150 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 $text2[] = "" . mysql_result($results_text,$x,"nick") . ": " . mysql_result($results_text,$x,"comment") . "\n"; Then you could use a foreach to go through it later. foreach ($text2 as $inputtext) { imagettftext($im, 10, 0, 40, 110, $black, $font, $inputtext); } Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/#findComment-571151 Share on other sites More sharing options...
mrbuter Posted June 21, 2008 Author Share Posted June 21, 2008 Oh I see...alright. That worked but how can I get the 110 to increment by 20 each time? I played around with it for a bit trying different things and if it didn't error out it would just move all of them (and they'd overlap). Thanks again DarkWater. Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/#findComment-571157 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 $pos = 110; foreach ($text2 as $inputtext) { imagettftext($im, 10, 0, 40, $pos, $black, $font, $inputtext); $pos += 20; } =) Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/#findComment-571159 Share on other sites More sharing options...
mrbuter Posted June 21, 2008 Author Share Posted June 21, 2008 More question (sure to become plural soon haha)! Is there a way to make the text wrap? Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/#findComment-571166 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 What do you mean? Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/#findComment-571167 Share on other sites More sharing options...
mrbuter Posted June 21, 2008 Author Share Posted June 21, 2008 nevermind I think I've got it all figured out. Thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/#findComment-571176 Share on other sites More sharing options...
DarkWater Posted June 21, 2008 Share Posted June 21, 2008 No problem. Post back if you have any more trouble. (I love PHP's image capabilities. So pro. ) Quote Link to comment https://forums.phpfreaks.com/topic/111268-solved-imagettftext-for-loop/#findComment-571178 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.