PHP: test line length for wrapping

assaultrifle109

New Member
How can I test if a chunk exceeds the image size and wrap that text to the next line. Not sure if I am even doing this correctly with my if statement.\[code\]$text="Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem http://somelongurl.com/then-we-make-it-super-long-with-some-more/ Lorem Ipsum Lorem Ipsum Lorem Ipsum";$string_chunks = explode(' ', $text);foreach ($string_chunks as $chunk) { if($end_x + $chunk > $image_width){ $start_x = 5; $start_y += 20; } $coords = imagettfbbox($fontsize, $angle, $font, $chunk); $end_x = $coords[0] + $coords[4] + 10; $color_to_draw = is_a_url($chunk) ? $linkcolor : $black; imagettftext($im, $fontsize, $angle, $start_x, $start_y, $color_to_draw, $font, $chunk); $start_x += $end_x;}\[/code\]With this code I get:\[code\]Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem http://somelongurl.com/then-we-make-it-super-long-with-some-more/Lorem Ipsum Lorem Ipsum Lorem Ipsum\[/code\]What I would like to happen is something like:\[code\]Lorem Ipsum Lorem Ipsum Lorem Ipsum Lorem http://somelongurl.com/then-we-make-it-super-long-with-some-more/Lorem Ipsum Lorem Ipsum Lorem Ipsum\[/code\]
 
Back
Top