I'm trying to use a PHP variable to add a href value for a link in an echo statement.
Here's a simplified version of the code I want to use. I know that I can't just add the variable into the echo statement, but I can't seem to find an example anywhere that works.
$link_address = '#'; echo '<a href="$link_address">Link</a>';
You need add quotes for your href , besides, you also need to use urlencode to encode the variable. . '">$compname</a>" ?? The last " should be a ' instead.
PHP link() Function$linkname = "mylink"; link($target, $linkname);
'</span>'; Additionally, you can do it inline by escaping the double quotes: echo "<span class=\"label-$variable\">$variable</span>"; Using double quotes also allows for special characters such as \n and \t .
The href attribute specifies the URL of the page the link goes to.
Try like
HTML in PHP :
echo "<a href='".$link_address."'>Link</a>";
Or even you can try like
echo "<a href='$link_address'>Link</a>";
Or you can use PHP in HTML like
PHP in HTML :
<a href="<?php echo $link_address;?>"> Link </a>
you can either use
echo '<a href="'.$link_address.'">Link</a>';
or
echo "<a href=\"$link_address\">Link</a>';
if you use double quotes you can insert the variable into the string and it will be parsed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With