简体   繁体   中英

Output text/link with variables inside

How can i make this output properly? Im using the right variables but i think im doing something wrong with quotations or what not.

<?php echo '<img src="' SITE_URL . 'img/' . $code '" title="Created by website.com" />' ?>

You need to join all the pieces of the string with . , the concatenation operator. You're missing several.

<?php echo '<img src="' . SITE_URL . 'img/' . $code . '" title="Created by website.com" />' ?>

echo also accepts multiple arguments, so you may use commas instead of periods:

<?php echo '<img src="', SITE_URL, 'img/', $code, '" title="Created by website.com" />' ?>
<?php echo '<img src="'. SITE_URL . 'img/' . $code .'" title="Created by website.com" />' ?>

You can do it multiple ways, inline with the HTML

<img src="<?= $SITE_URL ?>" title="..."/>

Or by echoing the whole string in PHP

<?php
    echo '<image src="' . $_SITE_URL . '" title="..."/>';
?>

If you do it in PHP, you need to make sure you use quotations correctly, escape characters as needed, and join all strings with a .

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