Skip to content Skip to sidebar Skip to footer

Can I Hide Broken Images?

I am trying to create a sidebar for which I can specify the image in the back-end of my wordpress cms using custom fields, now I have gotten it to work, with just one little bug, i

Solution 1:

You could try something like

<!--here is the HTML markup--><divid="inner_content_right"><imgsrc="<?phpif (@getimagesize($side)) echo$side; ?>" /></div>

Solution 2:

Thanx guys, I got it to work with this code!

//check if the string is a valid URLfunctioncheckURL($url)
{
    return preg_match('|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i', $url);
}

//returns a image with a valid URL or nothing at allfunctionvalidateImage($one){
if(!checkURL($one))
{
    $errMsg .= "Please enter valid URL including http://";
    //return $errMsg;
} else {
    $headers = get_headers($one, 1);
    $return = $headers[0];
    if($return!='HTTP/1.1 404 Not Found'){
        $string = "<img src='$one' />";
        return$string;
    }
    }
}

Thanx for all your help!

Post a Comment for "Can I Hide Broken Images?"