Docxpresso 库在渲染中忽略符号和与号

我正在使用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 >>”。


忽然笑
浏览 113回答 1
1回答

噜噜哒

如果你输出到HTML,然后特殊字符<,>,&,和"必须进行转义。使用内置htmlspecialchars()函数来做到这一点。另请注意,heredoc 格式对于输出大文本块要好得多,尤其是在处理引号和内插值时。$value = "MINUTA >> << &&&";$value = htmlspecialchars($value);// $value is now "MINUTA &gt;&gt; &lt;&lt; &amp;&amp;&amp;"$html = <<< HTML&nbsp; <style>&nbsp; &nbsp; &nbsp; &nbsp;* {font-family: Arial; font-size: 8pt}&nbsp; </style>&nbsp; <p style="text-align: center;"><strong><u>$value</u></strong></p>HTML;$doc = new \Docxpresso\createDocument();$format = ".odt";$doc->html([&nbsp; &nbsp; "html" => $html,&nbsp; &nbsp; "encoding" => "UTF-8"]);$doc->render("sample$format");header("Location: ../creditogarveh/sample$format");
打开App,查看更多内容
随时随地看视频慕课网APP