PHP validation URL is a valid function
There are two types of authentication URLs that use regular expressions to verify that URLs are appropriate URL rules, and the other is to use a function to access the specified URL to see if it is normal to access, if the normal access to natural is a legitimate URL address.
Example 1
The code is as follows |
|
function Isvalidurl ($url) { $patern = '/^http[s]?:\/\/'. ' (([0-9]{1,3}\.) {3} [0-9] {1,3} '. URL-199.194.52.184 in IP form '|'. Allow IP and domain (domain name) ' ([0-9a-z_!~*\ ' ()-]+\.) *'. Level three domain validation-www. ' ([0-9a-z][0-9a-z-]{0,61})? [0-9a-z]\.] Second-level domain validation ' [a-z]{2,6}] '. Top-level domain validation. com or. Museum ' (: [0-9]{1,4})? '. Port-: 80 ' ((\/\?) | '. If the file part is verified with a file ' (\/[0-9a-za-z_!~\*\ ' \ (\) \.; \?:@&=\+\$,%#-\/]*)?) $/'; if (!preg_match ($patern, $url)) { Die (' You have entered a problem with the URL format, please check! '); } } |
Example 2
The above example just verifies that the URL is not normal and does not mean that it can be accessed, we can use the method like the Curl function
The code is as follows |
|
$url = "Http://www.45it.net"; $curl = Curl_init ($url); curl_setopt ($curl, Curlopt_nobody, true); $result = curl_exec ($curl); if ($result!== false) { $statusCode = Curl_getinfo ($curl, Curlinfo_http_code); if ($statusCode = = 404) { echo "URL not Exists" } Else { echo "URL Exists"; } } Else { echo "URL not Exists"; } |
In addition to this function you can use a lot of PHP functions such as file, file_get_contents (), fopen function to detect.
http://www.bkjia.com/PHPjc/918725.html www.bkjia.com true http://www.bkjia.com/PHPjc/918725.html techarticle php verifies that the URL is valid for a function verification URL there are two ways to use regular expressions to verify that the URL is the appropriate URL rule, and the other is to use the function to access the specified URL to see if it can be positive ...