Forum


Replies: 8   Views: 3935
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.