Variable substitution within HEREDOC literal

182 Views Asked by At

i would to create a pdf file with TCPDF library files. and i would to use a specified and dynamic file name in the html code that then will render to pdf file. i use the following code to do this but doesn't work:

$html = <<<EOD
<div>
    </br>
    <img src="../tcpdf/pdffirst.png" width="500" height="800" alt=""/>
    <img src="../charts/".$filename."-most.png" width="500" height="250" alt=""/>
    </br>
</div>
EOD;

when i use this, the png file doesn't show in the pdf file. but when i use a static address like:

<img src="../charts/mychart-most.png" width="500" height="250" alt=""/>

the png file correctly show's in the pdf file. how can i use a dynamic file name in EOD element? thanks...

1

There are 1 best solutions below

0
On BEST ANSWER

You have don't need to close/open quotes for the variable. Use this code instead:

$html = <<<EOD
    <div>
        </br>
        <img src="../tcpdf/pdffirst.png" width="500" height="800" alt=""/>
        <img src="../charts/$filename-most.png" width="500" height="250" alt=""/>
        </br>
    </div>
EOD;