1

how can i replace php variable into html content by using mpdf? for example below code, i want to display variable purchasetype in html content.

<?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();
2

2 Answers 2

1
<label> variable here :  '.phpvariable.' </label>

break string and add it to the text.

If you use ", you can use PHP variables directly like this

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

but as you have used ', you can break the string and concatenate a value.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you @Danyal Sandeelo for your explanation and answer!!
0
$html = '<html>'.
'<body>'.
'<label> variable here :  '. $phpvariable .' </label>'.
'</body>'.
'</html>';

try like this

1 Comment

Thank you @Vinod Selvin!! It's working too

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.