If by a valid URL you mean something that is not 404, then you can use get_headers() and look for 404 in the first returned element of the array.
$url = 'http://google.com'; list($status) = get_headers($url); if (strpos($status, '404') !== FALSE) {
Alternatively, you can look for 200 , which would be a normal happy request :)
source share