Mar
02
2009

New function url_exists()

We all know the function file_exists() to check if a file exists on the local server.
But, if you want to check if an url is correct, this isn’t possible with this function.

Therefor i searched the web, and found this on php.net:

        function url_exists($url) {
            $hdrs = @get_headers($url);
            return is_array($hdrs) ? preg_match('/^HTTP\\/\\d+\\.\\d+\\s+2\\d\\d\\s+.*$/',$hdrs[0]) : false;
        }

Didn’t think it would be that easy! Good luck with it ;)

Written by Rene Pot in: PHP Problems, Sugestions | Tags: , , , ,

No Comments »

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress | Aeros Theme | TheBuckmaker.com WordPress Themes