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();
sigmax bpo
  • 27
  • 1
  • 9
  • String interpolation should help: https://stackoverflow.com/questions/4676417/should-i-use-curly-brackets-or-concatenate-variables-within-strings – muradm Nov 19 '18 at 06:39
  • This question already answered here: https://stackoverflow.com/a/36525712/6730400 – Vinod Selvin Nov 19 '18 at 06:43

2 Answers2

0
<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.

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
0
$html = '<html>'.
'<body>'.
'<label> variable here :  '. $phpvariable .' </label>'.
'</body>'.
'</html>';

try like this

Vinod Selvin
  • 369
  • 2
  • 10