简体   繁体   中英

Insert variable and PDF tag into PHP code

This should be incredibly simple but i can't seem to figure it out.

I have the following code

<?php
$bookingid='12345';
    include_once('phpToPDF.php') ;
    //Code to generate PDF file from specified URL
    phptopdf_url('https://google.com/','pdf/', $bookingid.pdf);
    echo "<a href='pdf/$bookingid.pdf'>Download PDF</a>";
?>

It echo's correctly however when it comes to generate the pdf...

phptopdf_url('https://google.com/','pdf/', $bookingid.pdf);

...it misses out the fullstop so it generates 12345pdf whereas it should be 12345.pdf.

Again, i apologise for the probable simplicity of this but i can't seem to figure it out.

$bookingid.pdf

It tells php to concatenate variable $bookingid with constant pdf . Since constant pdf is undefined, it is casted to string and concatenated. Proper code will look like:

$bookingid . '.pdf'

or

"$bookingid.pdf"

This should be

$bookingid.".pdf"

PHP is seeing a string concatenation, concatenating pdf ' to $booking . pdf is an undefined string, so PHP helpfully assumes that you mean the text itself, but it misses the full stop you also need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM