function valid_url($str) { require 'AvailabilityService.php'; $service = new HelgeSverre\DomainAvailability\AvailabilityService(true); $domain = $str; // if (!$domain) { // return FALSE; // } $domain = preg_replace("(^https?://)", "", $domain); $available = $service->isAvailable($domain); if ($available) { return FALSE; } else { return TRUE; } /* if(filter_var($str, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED) == TRUE){ return TRUE; }else{ return FALSE; } */ //$pattern = "/^(http|https|ftp):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i"; // $pattern = "|^http(s)?://[a-z0-9-]+(.[a-z0-9-]+)*(:[0-9]+)?(/.*)?$|i"; /* $pattern = "/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/"; if (!preg_match($pattern, $str)) { return FALSE; } return TRUE; */ // $ch = @curl_init($str); // // @curl_setopt($ch, CURLOPT_HEADER, TRUE); // @curl_setopt($ch, CURLOPT_NOBODY, TRUE); // @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE); // @curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); // $status = array(); // preg_match('/HTTP\/.* ([0-9]+) .*/', @curl_exec($ch), $status); // echo '<pre>'; // print_r($status); // echo '</pre>'; // echo "dns->" . checkdnsrr($str, 'ANY'); // die; // if (@$status[1] == 200 || @$status[1] == 302) { // return TRUE; // } else { // return FALSE; // } }
<?php require 'vendor/autoload.php'; $service = new HelgeSverre\DomainAvailability\AvailabilityService(true); $testDomains = array('google.com', 'fasdf2342asdfcvcxv.org'); foreach ($testDomains as $domain) { $available = $service->isAvailable($domain); if ($available) { echo $domain . " is not registered\n"; } else { echo $domain . " is registered\n"; } }