Questions & Answers

How do I create a LineBreak every 60 characters ? FPDF / PHP

I would like to use this configuration and make a line break every 60 characters.

The example i saw on the other pages does not explain how i can make a line break every 60 characters.

$pdf->Text(77, 94, utf8_decode("$objet"));
Answers(1) :

You can use wordwrap to break sentences into multiple lines without breaking the word and without the line exceeding the desired length.

Then simply iterate the lines, increasing the Y coordinate on each iteration, adjust the Y coordinate as necessary to suit the size of your text.

$object = "This is a very long text that I want to break into multiple lines every 60 characters.";
$object_lines = wordwrap($object, 60, "\n", true);
$object_lines = explode("\n", $object_lines);
$y = 94;

foreach ($object_lines as $line) {
    $pdf->Text(77, $y, utf8_decode($line));
    $y += 10;