Add PHP Variable Inside Echo Statement as Href Link Address

Add PHP variable inside echo statement as href link address?

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>

Adding PHP variables to HTML href

Your code should like

<php should be <?php

Because you are already in php blog, then do not use again <?php..

$token =1;
$email =2;
$body='
<body>
<p>Use the link below to reset your password.</p><br>
<a href="http://localhost/wwi/view/pw_reset.php?token='.$token.'&email='.$email.'">Click here</a>
</body>';

Use php variables in a href

You should not read the file contents to the variable. you should actually include the file. comment added in code

try

ob_start(); //start output buffering
// no include your file this actually outputs the parsed variable and you
// capture it in optput buffer
include('attributes/twitter-share-currentBand.php');
$twitter= ob_get_clean(); //store the output to the variable and stop output buffering.

file_get_contents reads the contents of the file as it is and puts in the variable $twitter when you actually want the parsed value of attributes/twitter-share-currentBand.php

You should use output buffering as your attributes/twitter-share-currentBand.php actually outputs the value you required to store in variable.

Note: $bandName and $currentURL should be initialized before including the file.

Edit: Alternatively you can include the file directly instead of storing the output to a variable. like following.

<div class="col-md-offset-2 col-md-2">
<a href="<?php include('attributes/twitter-share-currentBand.php') ?>">
<div class="socials twitter">
</div>
</a>
</div>

How to put a link passing variable inside php echo

Simply, put your anchor link in if condition:

<?php
if (YOUR_CONDITION_HERE) {
echo '<a href="page2.php?Id='.$Id.'">Product</a>';
}
?>

OR

<?php
if (YOUR_CONDITION_HERE) {
?>
<a href="page2.php?Id=<?php echo $Id;?>">Product</a>
<?php
}
?>

Above condition will display your link only when your condition is TRUE.

Otherwise, it will hide.

How to add PHP variables to a href url

Try this,

<?php
@session_start();
$uid= $_SESSION['userid'];
?>
<a href="http://example.com/?uid=<?php echo $uid; ?>" >Your link text</a>

PHP : echo a href

Using single and double quotes, you avoid escaping issues. Try this:

echo '<p><a href="https://www.facebook.com/rscmovement" target="_blank">'. $post['message']. '</a></p>';


Related Topics



Leave a reply



Submit