2012-07-17 62 views
0

好吧,我一直在撞牆,試圖解決這個問題已經有幾個月了。我有一個傳統的MySQL數據庫,可以描述爲字符地獄。經過大量工作後,我能夠修復所有不正確顯示的字符,並將UTF-8(表格,整理,連接到數據庫,標題等)做成一切。如何正確顯示使用PHPWord的雙引號?

現在的問題是,當我嘗試使用PHPWord創建Word文檔時,雙引號(「)顯示爲其相應的html實體"。這是我獲勝的唯一障礙,所以如果有任何想法, 「倒挺心存感激

這裏是代碼:

include_once "../PHPWord.php"; 
include_once "../debug.php"; 

$file_name = "filename.docx"; 
header("Cache-Control: public"); 
header("Content-Description: File Transfer"); 
header("Content-Disposition: attachment; filename=$file_name"); 
//header("Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document"); 
header("Content-Type: application/vnd.ms-word; charset=utf-8"); 
header("Content-Transfer-Encoding: binary"); 

$index = 1218; 
$mysqli = new mysqli("host","user","pass","database"); 
$mysqli->set_charset("utf8"); 
$qry1 = "SELECT * FROM table WHERE index = $index ORDER BY field DESC"; 
$qry2 = "SELECT * FROM table2 WHERE index = $index"; 

$PHPWord = new PHPWord(); 
$section = $PHPWord->createSection(); 

$section->addText("Connection Encoding: ".$mysqli->character_set_name()); 
$section->addText("resuls"); 

$res1 = $mysqli->query($qry1); 
while($row = $res1->fetch_assoc()){ 
    $section->addText($row[name]); 
    $section->addText(mb_detect_encoding($row['name'])); 
} 

$section->addText("results2"); 

$res2 = $mysqli->query($qry2); 
while($row = $res2->fetch_assoc()){ 
    $section->addText(trim($row['title'])); 
    $section->addText(mb_detect_encoding($row['title'])); 
} 

$objWriter = PHPWord_IOFactory::createWriter($PHPWord,'Word2007'); 
$objWriter->save('php://output'); 
exit; 

結果,是這樣的:

book:"Book Title" 

,使f ar我嘗試了很多函數和解決方案,包括諸如html_entity_decode,轉義字符和修改的PHPWord文件等PHP函數,以防止他們在將文本添加到輸出時嘗試重新編碼文本。

在此先感謝。

回答

0

我假設你需要在你的查詢 或其他人使用 msqli_real_escape_string()

某個地方,也許這對你的解決方案:PHPWord從 phpWord handling of UTF-8

+0

感謝您的回答,我已經嘗試過您發佈的第二個鏈接,我一直得到相同的結果。第一個鏈接,當餵食數據庫時會派上用場,但到目前爲止,我的問題是,當我獲取信息時,即使禁用了魔術引號,php也會將我的引號轉換爲html實體。 – 2012-07-18 14:36:15

0

試用最新版本(0.8) GitHub。該版本處理了UTF-8問題。