现在的问题是,当我尝试使用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"
到目前为止,我已经尝试了很多函数和解决方案,包括PHP函数,如html_entity_decode,转义字符和修改过的PHPWord文件,以防止它们在将文本添加到输出时尝试重新编码文本。
提前致谢。
答案 0 :(得分:0)
我假设你需要使用 msqli_real_escape_string()
您查询中的某个位置 或者,也许这有你的解决方案: phpWord handling of UTF-8
答案 1 :(得分:0)
从GitHub尝试PHPWord的最新版本(0.8)。此版本已处理UTF-8问题。