Forum


Replies: 8   Views: 3874
Problem with accent in addtext and embedhtml
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 llouis  · 29-01-2013 - 09:09

Hello,

I try to integrate phpDocx3.0 with its the new feature to embed HTML in tables (great feature).
But I have to put also in the document some text with AddText.
And the text language is in french ... with some accents in the text I add with AddText and ALSO in the HTML text (in this last case, the accents are replaced by special characters like it's usual in HTML).
Here's a piece of code (built from your examples) to demonstrate my problem.
My questions are below the code

[code]<?php

require_once '../../classes/CreateDocx.inc';

$docx = new CreateDocx();

$docx->setEncodeUTF8();

$text = 'My line with accent: ù é è ê à ï ö î';

$htmltext = '<p>' . htmlentities($text, ENT_QUOTES) . '</p>';

$paramsText = array(
'b' => 'on',
'font' => 'Arial',
);

$docx->addText($text, $paramsText);

$paramsText = array(
'font' => 'Arial',
'rawWordML' => true

);

$myHTML = $docx->embedHTML($htmltext, array('rawWordML' => true));

$fragment = $docx->createWordMLFragment(array($myHTML));

$valuesTable = array(
array(
11,
$fragment
),
array(
$fragment,
22
),
);

$paramsTable = array(
'border' => 'single',
'border_sz' => 5,
'rawWordML' => false
);

$test = $docx->addTable($valuesTable, $paramsTable);

$docx->createDocx('../docx/example_text_mine');[/code]

1. If I run this code, the document is well produced (when I open it, it is not corrupted) BUT the HTML text in the table is not well rendered due to the call to setEncodeUTF8 function
2. If I comment the call to setEncodeUTF8 function and I run this code, the document is corrupted when I try to open it (because of the AddText call).
3. If I comment the call to setEncodeUTF8 function and also comment the AddText call, the document is well produced and not corrupted. And the HTML text in the table is well rendered.

Is there a bug in the library or is there a mistake in my code?
How can I do to well rendered my text with accent by calling AddText and by embedding, in the same time, HTML with accent in the tables ?

Thank you in advance for your responses.

Best regards.

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

Hello,

What IDE are you using?

Regards.

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

Just a text editor: Notepad ++

Why this question ?

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

According to your question about IDE, you perhaps think about the text encoding for the PHP source file.
Then to complete the previously described problem, my PHP file was ANSI encoded.

But I did more try by saving the source file with UTF-8 encoding (without BOM), then:
1. If I let the call to setEncodeUTF8 function, then both text (added by AddText and HTML embedded) are not well rendered.
2. If I comment the call to setEncodeUTF8 function, only the text added by AddText is well rendered, the html text added in the table shows bad characters.

Basically, by modifying the source encoding charset to UTF-8 (without BOM), the document is well produced (I mean no error occur when I open it with word) BUT I don't yet have the expected result ( to text with accent well rendered by adding with AddText and by embedding HTML in the same time)

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

Hello,

You're right, I wanted to know the default charset. We recommend to use UTF8 editor, and if you use UTF8 charset you can't invoke setEncodeUTF8 because PHP has error if you encode an UTF8 string.

Please send us your script http://www.phpdocx.com/contact. Don't paste the code because we need to check your file not just content.

Regards.

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

Hello

Unfortunately, it's not possible to attach some file in your contact form.
Could you provide a email address?

Best regards

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

Hello,

Contact us and we'll answer you.

Regards.

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

Hello,

If you remove htmlentities and you don't use setEncodeUTF8 the script works fine.

Regards.