Forum


Replies: 10   Views: 8847
Please fix 'parselinebreaks' option
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 fantasma  · 06-11-2014 - 15:46

UPDATE: phpdocx 6.0 added support for '\n\r', '\r\n', '\n', '\r', "\n\r", "\r\n", "\n", "\r" when using the parseLineBreaks option. Previous versions only support literal breaks: '\n\r', '\r\n', '\n', '\r'

Posted by admin  · 06-11-2014 - 16:33

UPDATE: phpdocx 6.0 added support for '\n\r', '\r\n', '\n', '\r', "\n\r", "\r\n", "\n", "\r" when using the parseLineBreaks option. Previous versions only support literal breaks: '\n\r', '\r\n', '\n', '\r'

Posted by fantasma  · 07-11-2014 - 09:09

Sorry, but it does not work ! I'm running Ubuntu 14.04, PHP 5.5 and phpdocx 4.1. and Ubuntu 12.04, PHP 5.3, phpdocx 4.1. On both platforms it does not work! I fixed it for me, replacing "\r\n" with '__LINEBREAK__' before replacing the variable. $break = '__LINEBREAK__'; $multiline = str_replace(array("\n\r", "\r\n", "\n", "\r"), $break, $text); You need to use double-quotes (") to make your code work. Please have a look at: http://php.net/manual/de/language.types.string.php#language.types.string.syntax.single Kind regards

Posted by admin  · 07-11-2014 - 09:57

UPDATE: phpdocx 6.0 added support for '\n\r', '\r\n', '\n', '\r', "\n\r", "\r\n", "\n", "\r" when using the parseLineBreaks option. Previous versions only support literal breaks: '\n\r', '\r\n', '\n', '\r'

Posted by fantasma  · 07-11-2014 - 12:55

I'm really sorry, but in my case the str_replace with single quotes just does not find the breaks (Tested with aptana, xdebug). By the way, i'm using Drupal 7 and im generating DOCX from the Drupal MySQL Database. Database encoding is UTF8. For the moment i can go on with my workaround and i'm not going to change the library :-) Thanks for your help and kind regards,

Posted by sigura  · 06-01-2016 - 16:35

I confirm that this is still an issue. Replacing the single quotes by double quotes works and fixes this issue.

We had this issue on our development environment as well as on our production environments.

I have replaced this in the CreatDocxFromTemplate file, and hoping this won't break in a future update.

Ps: using PHP 5.6.x on Ubuntu/CentOS

Posted by admin  · 06-01-2016 - 17:59

UPDATE: phpdocx 6.0 added support for '\n\r', '\r\n', '\n', '\r', "\n\r", "\r\n", "\n", "\r" when using the parseLineBreaks option. Previous versions only support literal breaks: '\n\r', '\r\n', '\n', '\r'

Posted by admin  · 07-01-2016 - 08:35

Hello,

We have tested it again using fresh installations of Ubuntu and CenOS and it works perfectly. We'd need to check it directly on your server, please write to contact[at]phpdocx.com

The most common mistake when working with parseLineBreaks is that you need to set line breaks as '\n' not "\n".

Regards.

Posted by quasydoc  · 22-01-2016 - 14:25

We also ran into this issue.

To reproduce it, try saving the contents of a textarea form field containing multiple lines of text to the database. If you then retrieve the field, and feed it into the replaceVariableByText() function with the parseLineBreaks option 'true', line breaks are not detected by phpdocx.

What "str_replace(array('\n\r', '\r\n', '\n', '\r'), '__LINEBREAK__', $value);" in the phpdocx source code does is look for the character '\', followed by 'r', followed by character '\', followed by 'n', or in hex notation: 5C 72 5C 6E, instead of 0D 0A.

It should work in the same fashion as the nl2br() php function.

Posted by admin  · 22-01-2016 - 15:10

UPDATE: phpdocx 6.0 added support for '\n\r', '\r\n', '\n', '\r', "\n\r", "\r\n", "\n", "\r" when using the parseLineBreaks option. Previous versions only support literal breaks: '\n\r', '\r\n', '\n', '\r'

Posted by admin  · 26-01-2016 - 12:16

Hello,

UPDATE: phpdocx 6.0 added support for '\n\r', '\r\n', '\n', '\r', "\n\r", "\r\n", "\n", "\r" when using the parseLineBreaks option. Previous versions only support literal breaks: '\n\r', '\r\n', '\n', '\r'

Regards.