Jump to content

if no image exists


V

Recommended Posts

I have parts in my script like this

 

 <img src="<?php echo $post_thumb; ?>" alt="" ?>

 

the var is just an image url I enter via a "new post" form. Sometimes I won't add images and I get that default broken image icon.

 

Right now I'm using if statements to make it go away

 

if(!empty($post_thumb)){
...show the image....

 

I'm just wondering. Instead of using if statements everywhere, is there just some kind of global function that can be used to remove all the broken img icons?

Link to comment
https://forums.phpfreaks.com/topic/206224-if-no-image-exists/
Share on other sites

If your using

<img src="<?php echo $post_thumb; ?>" alt="" ?>

then I guess not, Of course to could pre parse the output but I wouldn't recommend such a work-around,

 

another option would be to create a "missing-image.jpg" and then set $post_thumb to that

for example

if(empty($post_thumb){
  $post_thumb = "missing-image.jpg";
}

Link to comment
https://forums.phpfreaks.com/topic/206224-if-no-image-exists/#findComment-1078935
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.