Karl Friedchicken Karl Friedchicken - 6 months ago 12
PHP Question

how to make same link with many href using php?

i tried to find this answer in se but still not find it.
the example is like this :

<div class="article">
<img src="#" href="$link" /> <!--- same link --->
<h1><a href="$link">Head of Article</a></h1> <!-- same link --->
<p>Desc of article</p>
<a href="$link">Read</a> <!-- same link ---->
</div>

<!--example php --->
<?php
$link = "/article/blablabla.html" ;?>


i have tried to put the php in the top html and add echo but its not work. i want control the $link using the php . some like that. so, i will not tried to write it one by one. is that can ? thanks!

Answer
<!--example php --->
<?php
      $link = "/article/blablabla.html" ;
?>

<div class="article">
    <img src="#" href="<?php echo $link; ?>" /> <!--- same link --->
    <h1><a href="<?php echo $link; ?>">Head of Article</a></h1> <!-- same link ---> 
    <p>Desc of article</p>
    <a href="<?php echo $link; ?>">Read</a> <!-- same link ---->
</div>
Comments