Add PHP variable inside echo statement as href link address?
271,393
Solution 1
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>
Solution 2
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.
Solution 3
Basically like this,
<?php
$link = ""; // Link goes here!
print "<a href="'.$link.'">Link</a>";
?>
Solution 4
as simple as that: echo '<a href="'.$link_address.'">Link</a>';
Author by
jasonbradberry
Updated on July 09, 2022Comments
-
jasonbradberry almost 2 years
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>';