我正在使用Docxpresso 库来呈现文档。在 HTML 中呈现文本时,ODT 文件中的结果会忽略或消除与号“&”。如何修改库以使其不删除“&”?下面我留下我使用的代码:$html = ' <style> * {font-family: Arial; font-size: 8pt} </style> <p style="text-align: center;"><strong><u>MINUTA >> << &&&</u></strong></p>';$doc = new Docxpresso\createDocument();$format = '.odt'; //only .odt because I dont have licence$doc->html(array('html'=>$html, 'encoding' => 'UTF-8'));$doc->render('sample' . $format);header('Location: ../creditogarveh/sample'.$format);我希望存档中的输出类似于:“MINUTA >> << &&&”,但实际输出:“MINUTA >>”。
1 回答
噜噜哒
TA贡献1784条经验 获得超7个赞
如果你输出到HTML,然后特殊字符<,>,&,和"必须进行转义。使用内置htmlspecialchars()函数来做到这一点。
另请注意,heredoc 格式对于输出大文本块要好得多,尤其是在处理引号和内插值时。
$value = "MINUTA >> << &&&";
$value = htmlspecialchars($value);
// $value is now "MINUTA >> << &&&"
$html = <<< HTML
<style>
* {font-family: Arial; font-size: 8pt}
</style>
<p style="text-align: center;"><strong><u>$value</u></strong></p>
HTML;
$doc = new \Docxpresso\createDocument();
$format = ".odt";
$doc->html([
"html" => $html,
"encoding" => "UTF-8"
]);
$doc->render("sample$format");
header("Location: ../creditogarveh/sample$format");
- 1 回答
- 0 关注
- 112 浏览
添加回答
举报
0/150
提交
取消