Forum


Replies: 1   Views: 2625
Wrap a text from db
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 27-01-2018 - 15:37

Hello,

UPDATE: phpdocx 12 added the parseLineBreaks option to the addText method.

If you are using the addText method and you want to add a line break for each \n, the only solution would be to use the explode function of PHP to generate an array for each \n and then iterate it to add as many lines as needed with addText:

$texts = explode('\n', $var);
foreach ($texts as $text) {
   $docx->addText($text);
}

If you are using a template and methods such as replaceVariableByText (https://www.phpdocx.com/api-documentation/templates/replace-variable-text-Word-document), you can use the parseLineBreaks option to replace \n by a line break automatically.

Regards.