Forum


Replies: 5   Views: 4363
Lib throws exception when including variables containing & and parselinebreaks set to true
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 jdespatis  · 15-07-2014 - 13:00

I'd like to include breaks in my word file, so I use following code: $docx = new \CreateDocxFromTemplate("replacePlaceholderImages1.docx"); $docx->replaceVariableByText(array("FOO" => "some & text \n foo"), array("target" => "header", "parseLineBreaks" => true)); $docx->createDocx('/tmp/example_replacePlaceholderImages_1'); But I get an exception: ContextErrorException: Warning: DOMDocument::createElementNS(): unterminated entity reference text in [...]/phpdocx/classes/CreateDocxFromTemplate.inc line 1297 Exception seems due to the presence of '&' symbol

Posted by admin  · 15-07-2014 - 14:43

Hello, Yes, you need to escape that character and others like '&', '>'... Regards.

Posted by jdespatis  · 15-07-2014 - 15:59

Ok thanks, As I've no problem with & symbol when I use the default behavior (parseLineBreaks == false), then I need to protect some symbols only when parseLineBreaks is set to true right ? And then 2 questions: * which php function should I use to protect those symbols when parseLineBreaks is activated ? htmlspecialchars, another function ? * why not performing automatically this character convertion in the lib ? as the replaceVariableByText only accepts text as input, no Word fragment or so on, no?

Posted by admin  · 15-07-2014 - 16:32

Hello, Please send the questions to contact@phpdocx.com to get the support. Regards.

Posted by andywaters  · 02-03-2015 - 12:39

I have the same issue, was this ever resolved? Regards, Andy

Posted by admin  · 02-03-2015 - 13:18

Hello, That issue was fixed for all phpdocx versions. Regards.