سؤال

Hi i have a code here which previously works. it gets text input and prints the input using imagettftext on a jpg. i used word wrap and explode to assign where the text should appear. I have seen other post almost similar to this but i dont want to use for loops and counters or things as such. what do you think im doing wrong with my code? it previously works fine but now it's not working. thanks in advance for any help. here's my code. please feel free to edit it.

$story = "My story begins with " . $_POST['story'];

$newtext = wordwrap($story, 35, "\n", true);
$newertext = explode("\n", $newtext);
imagettftext($im, 8, 0, 280, 386, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 398, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 410, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 422, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 434, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 446, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 458, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 470, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 482, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 494, $black, $font2, $newertext);
imagettftext($im, 8, 0, 280, 506, $black, $font2, $newertext);
هل كانت مفيدة؟

المحلول

explode returns an array, please check on how arrays are accessed in PHP.

$story = "My story begins with " . $_POST['story'];

$newtext = wordwrap($story, 35, "\n", true);
$newertext = explode("\n", $newtext);
imagettftext($im, 8, 0, 280, 386, $black, $font2, $newertext[0]);
imagettftext($im, 8, 0, 280, 398, $black, $font2, $newertext[1]);
imagettftext($im, 8, 0, 280, 410, $black, $font2, $newertext[2]);

etc

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top