replacing non existing images with images


I am using google base to pull content and some of the content has image links that are broken, this is resulting in me having 100 images and 5 broken images on a page.

Is there any way to say .if image not found then display /no_image.jpg.?
Who is Participating?

Improve company productivity with a Business Account.Sign Up

-pio-Connect With a Mentor Commented:

I suggest to use JS and IMG OnError property to do it.

<script language="JavaScript" type="text/javascript">
function ImgError(source){
        source.src = "images/noimage.gif";
        source.onerror = "";
        return true;
<div><img src="images/this_image_doesnt_exists.jpg" onerror="ImgError(this)"></div>

Open in new window

cdaugustinConnect With a Mentor Commented:

you could try to using .htaccess rewrite if you first get the images on your server (check the following link : ) if you dont download the images locally then your could employ either a javascript solution (maybe put all the images on an array, try to load them with js, and if it fails load a default image) OR a server side solution where you would do a HEAD request for each image and treat acordingly the answer  (some details at :

movieprodwAuthor Commented:
Those are both great ideas!

Is there a php way to do it?

here it the code,

<div class="image"><a href="listing.php?gid=<?=$aProperty[$j]["sId"]?>"><img src="<?php echo $aProperty[$j]["sImg"]; ?>" title="Real Estate, <?php echo $aProperty[$j]["sLocation"]; ?>" width="96" height="66" border="0" /></a></div>
Here it is.

<div class="image">
<a href="listing.php?gid=<?=$aProperty[$j]["sId"]?>">
<img src="<?php if (file_exists($aProperty[$j]["sImg"])) { echo $aProperty[$j]["sImg"]; } else { echo "images/nopicture.jpg"; } ?>" title="Real Estate, <?php echo $aProperty[$j]["sLocation"]; ?>" width="96" height="66" border="0" />

Open in new window

movieprodwAuthor Commented:
interestingly enough that replaced all of the images with my no image!

I think its because they are getting pulled from google and they are not being pulled from the server like a normal file?

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.