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>';
Any pointers appreciated.
This question is related to
php
variables
echo
href
double-quotes
as simple as that: echo '<a href="'.$link_address.'">Link</a>';
Basically like this,
<?php
$link = ""; // Link goes here!
print "<a href="'.$link.'">Link</a>";
?>
You can use one and more echo statement inside href
<a href="profile.php?usr=<?php echo $_SESSION['firstname']."&email=". $_SESSION['email']; ?> ">Link</a>
link : "/profile.php?usr=firstname&email=email"
This worked much better in my case.
HTML in PHP: <a href=".$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 want to print in the tabular form with, then you can use this:
echo "<tr> <td><h3> ".$cat['id']."</h3></td><td><h3> ".$cat['title']."<h3></</td><td> <h3>".$cat['desc']."</h3></td><td><h3> ".$cat['process']."%"."<a href='taskUpdate.php' >Update</a>"."</h3></td></tr>" ;
Source: Stackoverflow.com