php添加一个带变量的href

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>';