Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.