how can I change the src of an image according to the value inside a tag?

Viewed 52

<div class="card-body border-0">
    <img class="img-fluid" src="icons/Termo.png" alt="">
</div>

<td>
    <?php echo $value_termo ?>
</td>

I have this code, with a value that comes from a txt file, this value returns a boolean, if it is true, I need to change the image.

how can I do this?

2 Answers

Don't understand what you are expecting exactly.

assuming this is

 <div class="card-body border-0">
      <?php if(is_bool($value_termo)=== true){?>
           <img class="img-fluid" src="alternate_image_path" alt="">
      <?php }else { ?>
           <img class="img-fluid" src="icons/Termo.png" alt="">
      <?php } ?>
  </div>

  <td>
        <?php echo $value_termo; ?>
  </td>

You mean like this?

<div class="card-body border-0">
    <img class="img-fluid" src="<?= $value_termo ? 'icons/True.png' : 'icons/Termo.png' ?>" alt="">
</div>

<td>
    <?php echo $value_termo ?>
</td>
Related