为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
忽然笑 2021-06-14 13:01:20
我正在使用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 &gt;&gt; &lt;&lt; &amp;&amp;&amp;"


$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");


查看完整回答
反对 回复 2021-06-19
  • 1 回答
  • 0 关注
  • 112 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信