Using PHP, I display a link to a picture in src, but this picture is not always there and it turns out that a block with a picture remains empty and takes up space. How can I hide a block with an empty src?
CodePudding user response:
I will answer as I Understand the question,
I will assume you have a variable with the picture URL, and that data is send through POST method
<?php
$picURL = $_POST['picURL'];
if(!isset($picURL)){
echo "<img src=${picURL}>";
}
?>
here what I am doing is checking whether the variable is set or not if the $picURL variable is set I assume there is a URL and render the image.
CodePudding user response:
You can do it using PHP.
<?php if(!empty($img_url)){ ?>
<img src ="<?php echo $img_url; ?>" alt ="Image name" />
<?php } ?>
It will only display the image in which src is not empty.