Forum


Replies: 4   Views: 3416
Problem with character '&' generating docx (free version)
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 darkangelo  · 13-07-2011 - 17:33

I have a problem when I generate a document, if there is at least one word with the character ampersand (&) the document crash and doesn't open, I tested in the sample form of the section Demo of this site and it's crashed too, here is an example for your test, please help me and sorry for my english is not very well.

$paramsHeader = array(
'font' => 'Humnst777 BT',
'b' => 'single',
'color' => '008000',
'jc' => 'center',
'sz' => 13
);

$docx = new CreateDocx('doc');
$docx->setEncodeUTF8();
$docx->addText('Testing & character', $paramsHeader);

$docx->createDocx('sample');

Posted by area51  · 11-04-2013 - 12:13

Hi,

This is also a problem with the PRO version.
Having ampersand within any variable will crash the document beyond usability.
I've solved the issue by replacing the ampersand with & before calling addTemplateVariable.
IMHO all XML reserved characters will crash the document like < or >.

Looking forward for a small update to resolve the issue.

Kind regards,
Gregor Streng






Posted by admin  · 11-04-2013 - 12:13

Hi,

You have to replace the '&' character with his HTML equivalent &# 38; (without spaces). Here you have a conversion table http://www.asciitable.com


Or entering the parameter value within a CDATA section
[code]$docx->addText(’<![CDATA[Testing & character]]>’, $paramsHeader);[/code]


Regards.

Posted by darkangelo  · 11-04-2013 - 12:13

Thanks a lot, it's work excellent