Replies: 1   Views: 2481
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 Expertise  · 27-01-2018 - 13:41

Goodmorning everyone !

I use PhpDocX to get text from fields in a db and generate a word file.
Does anyone know how to wrap a text from DB?

For example:

The text in a TEXT field of the DB:
my name \ n
is micky \ n

The result by generating the word file is:
hello, my name is micky

How can I keep the desired formatting even in the word file?

Hello everyone and excuse me for my bad english ;-)

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


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) {

If you are using a template and methods such as replaceVariableByText (, you can use the parseLineBreaks option to replace \n by a line break automatically.