问题描述
我使用的是使用 composer 安装的 MPDF。我在 MysqL 数据库中存储了一些内容,其中包括 HTML 标签和文本。我希望用户能够创建和编辑他们自己的信件。 当我去打印 pdf 时,我得到一个 PDF 页面,页面上显示了 HTML 标签。奇怪的是;如果我获取该输出并将其复制并传递到 PHP 页面中的 WriteHTML() 函数中,该页面将以正确的文本和格式呈现。这似乎不是 HTML 标记的问题,而是 Mpdf 如何呈现 HTML 的问题。
这是发送到 $WriteHTML 之前的 $headder 输出:
<h1 style="text-align: center;">Baddeck Academy Scholarships</h1> <h6
style="text-align: center; line-height: 1;"><span style="color:
#e67e23;">320 Shore Rd.</span></h6> <h6 style="text-align: center;
line-height: 1;"><span style="color: #e67e23;">Baddeck,NS</span></h6>
<h6 style="text-align: center; line-height: 1;"><span style="color:
#e67e23;">B0E 1B0</span></h6>
<?PHP
include('connect.PHP');
$id = (filter_var($_GET['id'],FILTER_SANITIZE_STRING));
$sql = "SELECT * FROM `money_letters_contents` WHERE `id` = '$id' LIMIT 0,1000";
$result = MysqLi_query($conn,$sql);
if (MysqLi_num_rows($result) > 0) {
// output data of each row
while($row = MysqLi_fetch_assoc($result)) {
$headder = ($row['headder']);
$body = ($row['body']);
$footer = ($row['footer']);
}
} else {
}
$html = $headder;
//==============================================================
//==============================================================
//==============================================================
require_once __DIR__ . '/vendor/autoload.PHP';
$mpdf = new mPDF();
$mpdf->WriteHTML("$headder");
$mpdf->WriteHTML("$body");
$mpdf->Output();
exit;
解决方法
确定后寻找这个答案,并与来自@Finew我的帮助3天看了看说我在外面得到服务器的数据的方式,我创建了另一个步骤,其中,我拿着的mysqli $行并保存它作为另一个变量,然后我做了htmlspecialchars_decode该变量。这似乎工作,现在产生正确的结果。
因此,对于任何人都希望看到我在这里做的是工作的代码。
?php
include('connect.php');
$id = (filter_var($_GET['id'],FILTER_SANITIZE_STRING));
$sql = "SELECT * FROM `money_letters_contents` WHERE `id` = '$id' LIMIT 0,1000";
$result = mysqli_query($conn,$sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$headder = ($row['headder']);
$body = ($row['body']);
$footer = ($row['footer']);
}
} else {
}
$headder1 = htmlspecialchars_decode($headder);
$body1 = htmlspecialchars_decode($body);
$html = $headder;
//==============================================================
//==============================================================
//==============================================================
require_once __DIR__ . '/vendor/autoload.php';
$mpdf = new mPDF();
$mpdf->WriteHTML("$headder1");
$mpdf->WriteHTML("$body1");
$mpdf->Output();
exit;
感谢大家谁看了看这个问题。