简体   繁体   中英

php add a href with variable

I am trying to make php display the images as links however I cannot make the same images work as links. I want to have the images clickable so they can be opened to their full size.

small images:

echo '<img src="'.$num.'" width=200 hight = 200 alt="random image">'."&nbsp;&nbsp;"; 

I want to make them linked to their full image size, I am trying the below but in vain:

echo '<a href="'.$num.'"<img src="'.$num.'" width=200 hight = 200 alt="random image">'."&nbsp;&nbsp;";

Kindly assist

Your img tag isn't surrounded by your a tag properly. As long as $num is a valid URL, try

echo '<a href="'.$num.'"><img src="'.$num.'" width="200" height="200" alt="random image"></a>&nbsp;&nbsp;';

The HTML code you want to obtain:

    <a href="***"><img src="***" width="200" height="200" alt="***"></a>

with

  • a closing > at the end of opening a ,
  • an E in height,
  • no extra spaces around = and
  • a closing </a>

In PHP:

   echo '<a href="'.$num.'"><img src="'.$num.'" width="200" height="200" alt="***"></a>';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM