MPDF - 在 html 输出中包含 PHP 变量

MPDF - Including PHP Variables in html output

如何使用 mpdf 将 php 变量替换为 html 内容?例如下面的代码,我想在 html 内容中显示变量 purchasetype

<?php

$PurchaseType = "Cash";
$html = '
<html>
<body>
<label> variable here :  "phpvariable" </label>
</body>
</html>
';

$path = (getenv('MPDF_ROOT')) ? getenv('MPDF_ROOT') : __DIR__;
require_once $path . '/vendor/autoload.php';
$mpdf = new \Mpdf\Mpdf([
    'margin_left' => 20,
    'margin_right' => 15,
    'margin_top' => 48,
    'margin_bottom' => 25,
    'margin_header' => 10,
    'margin_footer' => 10
]);
$mpdf->SetProtection(array('print'));
$mpdf->SetTitle("Acme Trading Co. - Invoice");
$mpdf->SetAuthor("Acme Trading Co.");
$mpdf->SetWatermarkText("Paid");
$mpdf->showWatermarkText = true;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->WriteHTML($html);
$mpdf->Output();
<label> variable here :  '.phpvariable.' </label>

断开字符串并将其添加到文本中。

如果你使用",你可以像这样直接使用PHP个变量

$html="textual data $varibale_php and rest of the text.";

但正如您使用的 ',您可以断开字符串并连接一个值。

$html = '<html>'.
'<body>'.
'<label> variable here :  '. $phpvariable .' </label>'.
'</body>'.
'</html>';

这样试试