Hi, I want to be able to put a simple if statement or something to stop broken images looking crap! I wan't a page to show an image of my choice if the img src isn't there. Basically - I'm adding the favicon.ico of others websites to my website... but if they havn't got a favicon I don't want it to show a placeholder - I want it to display a default icon. Something along the lines of if img src broken then display default.ico PHP: If anyone has any ideas, I'd be very appreciative.
function remote_file_exists($url) { $headers = @get_headers($url); return preg_match('/^HTTP\/1\.\d\s+200/i', $headers[0]); } // Example: if (remote_file_exists('http://example.com/favicon.ico')) { // Exists } else { // Doesn't exist } PHP: Untested but should work. (PHP 5 is needed though)