2017-01-23 49 views
0

嗨我有一個問題,與PHP單詞。當我在我的文件中使用重音字符時,該文件已損壞,無法打開。Phpword和重音字符

<?php 
require_once 'PHPWord.php'; 
$PHPWord = new PHPWord(); 

$document = $PHPWord->loadTemplate('Documents/LM.docx'); 
$document->setValue('Value1', "example with accent évian"); 
$document->save('Documents/LMD.docx'); 

?> 

回答

0

我假設你的代碼生成的字文件在沒有特殊重音字符的情況下使用時沒有損壞。但無論如何,你可以試試下面的版本嗎? loadTemplate函數在0.13.0版本中不推薦使用,而應該使用TemplateProcessor + htmlspecialchars wrapper應該通常用於文本內容。

$templateProcessor = new PhpWord\TemplateProcessor('Documents/LM.docx'); 
$templateProcessor->setValue('Value1', htmlspecialchars('example with accent évian', ENT_COMPAT, 'UTF-8')); 
$templateProcessor->saveAs('Documents/LMD.docx'); 

這是爲我工作沒有問題與PhpWord 0.13.0