Forum


Replies: 7   Views: 3595
Escape required?
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 nachtschicht  · 15-11-2011 - 10:23

Hi,

I am using phpdocx v2.4 and would like to add some data from my database to a docx document. As long as I just insert "static" text everything works fine. However after adding the content from the database the docx is no longer valid and word refuses to open it. Are there any special chars which I need to escape when using $docx->addText()?

Thanks for your help

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

Hello,

Please paste a line that brokes DOCX.

Regards.

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

Hi,

the error message is:
[img]http://www.security-blog.eu/wp-content/uploads/2011/11/docx_error.png[/img]

the mentioned area within the xml file is:
[img]http://www.security-blog.eu/wp-content/uploads/2011/11/docx_area.png[/img]

After replacing the strange symbols with an proper ' the docx opened as expected. It looks like an charset conversation problem :-( in some way. :-(

... I just implemented the following (temporary) function to avoid having the problem in my development environment again...
[code]private function ParseOutput($string) {
$out = preg_replace("/[^a-zA-Z0-9\s.,!?&%$§-_:;#+*=)(]/", "", $string);
return $out;
}[/code]

Any suggestion for a final solution would be appreciated.

Thanks

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

I'am having the same problems

for example

$objDocx->addTemplateVariable('TGW_Prijs', ''.$TGW_Prijs.'');

The template doesn't like the € sign and the ' ' (quotes) and the ; sign

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

Hi,

hope they come up with an update soon - I am not going to use this product in production if this problem is not going to be fixed...

Kind regards,
Johannes

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

Hello,

Did you try using setEncodeUTF8 method?. Also you must use an UTF8 editor; if you are using Eclipse you must change default charset (cp1252) to UTF8.

Regards.

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

Eclipse is set to UTF-8 (Default for all my projects), the server is using utf8, too.