我正在使用mPDF将php mysql导出为pdf。运行得很好。但是,如果内容中包含任何'(单引号),我将面临一个问题。请参见下面的代码。例如,如果我写Name,那么我没问题,但是如果我写Name,则代码不起作用。甚至,如果$ a1的值是David的值,那么它将不起作用。有人可以帮我吗?
$html = '
<html>
<head>
<table>
';
include("database.php");
$result = mysqli_query($mysqli, "SELECT * FROM test");
while ($row = mysqli_fetch_array($result))
{
$html .='
<tr>
<td>Name: ' . $row['a1'] . '</td>
<td colspan="3">Designation:' . $row['a2'] . '</td>
</tr>
<tr>
<td>Contact phone number:' . $row['a3'] . '</td>
<td colspan="3">E-mail:' . $row['a4'] . '</td>
</tr>
';
}
$html .= '
</table>
</body>
</html>
';
$path = (getenv('MPDF_ROOT')) ? getenv('MPDF_ROOT') : __DIR__;
require_once $path . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf([
'margin_left' => 5,
'margin_right' => 5,
'margin_top' => 31,
'margin_bottom' => 20,
'margin_header' => 4,
'format' => 'A4',
'orientation' => 'P',
'margin_footer' => 10
]);
$mpdf->SetHeader('Test');
$mpdf->setHTMLHeader('<img src="logo.jpg"/>');
$mpdf->setHTMLFooter('<img src="logo.jpg"/>');
$mpdf->SetTitle("Test");
$mpdf->SetAuthor("ohidul islam");
$mpdf->allow_charset_conversion = true;
$mpdf->charset_in = 'iso-8859-4';
$mpdf->SetDisplayMode('fullpage');
$mpdf->WriteHTML($html);
$fname=Testform.".pdf";
$mpdf->Output($fname, 'I');