2017-01-22 196 views
0

我使用COM來生成來自PHP的word文檔。當將字符轉換爲生成無用漢字和一些數字的單詞書籤模板時,我有一個大問題。來自php的特殊字符/統一碼/特殊符號word

這裏是我的PHP字符串值 - Brüel & Kjær

這是Word文檔的文本後生成 - Brüel & Kjær1墄

這裏是我的轉換方法在PHP中:

$text="Brüel & Kjær"; 
$text = iconv(mb_detect_encoding($text, mb_detect_order(), true), "UTF-8",$text); 
$text = htmlspecialchars_decode($text); 
$text=html_entity_decode($text, ENT_QUOTES, 'utf-8'); 

這是如何將COM書籤變量添加到值的:

$PHPWord = new COM("word.application", NULL, CP_UTF8); 
$PHPWord->Documents->Open(realpath($template)); 
$bookmark = $PHPWord->ActiveDocument->Bookmarks("bookmark1"); 
$bookmark = $bookmark->Range; 
$bookmark->Text=$text; 
$PHPWord->Documents[1]->SaveAs('temp/' . $template); 

我是我的代碼中的字符轉換問題。但我在互聯網上搜索,我找不到我的問題的工作解決方案。你能幫我解決這個問題嗎?

是他們的方式發送HTML到這個書籤或任何轉換?

回答

0

OMG幾乎完成這件事:

$text="Brüel & Kjær"; 

$PHPWord = new COM("word.application", NULL, CP_UTF8); 

替換爲:

$PHPWord = new COM("word.application"); 
$PHPWord->Documents->Open(realpath($template)); 
$bookmark = $PHPWord->ActiveDocument->Bookmarks("bookmark1"); 
$bookmark = $bookmark->Range; 
$bookmark->Text=html_entity_decode($text); 
$PHPWord->Documents[1]->SaveAs('temp/' . $template);