php variable inside echo ‘html code’

You concatenate the string by ending it and starting it again:

echo '
<div>
<a class="fragment" href="' . $url . '">
<div>';

Though I personally prefer to stop the PHP tags and start them again (if I have a lot of HTML) as my IDE won’t syntax highlight the HTML as it’s a string:

?>
    <div>
        <a class="fragment" href="https://stackoverflow.com/questions/19773738/<?php echo $url; ?>">link</a>
    </div>
<?php

Leave a Comment