Forum


Replies: 5   Views: 4307
Html and utf-8
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 honzakuchar  · 11-07-2011 - 11:37

Hi,

I have encoding problem with adding HTML into docx document. I'm using UTF-8 editor, so input is properly UTF-8 encoded. When I try this code:
[code]
$docx = new CreateDocx();
$docx->addText("ěščřžýáíéé");
$docx->createDocx("test");
[/code]
Text is [i]properly[/i] encoded. But when I try this example:
[code]
$docx = new CreateDocx();
$docx->addHTML("<b>ěščřžý</b>áíéé");
$docx->createDocx("test");
[/code]
It is non-properly encoded like on this image:
[img]http://projekty.mujserver.net/Bugreports/PHPDocx/WordScreenshot1.png[/img]

So question is simple: [b]How to set encoding to UTF-8 in "word/html"?[/b]

PS: Temporary workaround:
[code]
$docx = new CreateDocx();
$docx->addHTML(iconv("UTF-8","Windows-1250","<b>ěščřžý</b>áíéé"));
$docx->createDocx("test");
[/code]

------------
Using PHP 5.3.1, PHPDOCX v2.3

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

[code]$docx->setEncodeUTF8();[/code] doesn't help you ?

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

No, it activates utf8_encode function = Encodes an ISO-8859-1 string to UTF-8 (source: PHP documentation). And I have UTF-8 encoded string on input.

So problem in other words is:
->addText() accepts UTF-8 strings
->addHtml() accepts Windows-1250 encoded HTML (default in IE)

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

:-)

I found simple solution.
[code]$docx = new CreateDocx();
$docx->addHTML(
"<head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><b>ěščřžý</b>áíéé</body>"
);
$docx->createDocx("test");[/code]

Is possible to put it into official source?

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

Hi,

We're going to check this issue to be solved in the next version of phpdocx pro.

Regards.