How to check validity of an URL
How to check validity of an URL. 1. Using Regex if (ereg(“^(http|https|ftp)\://[a-zA-Z0-9\.-]+\.[a-zA-Z0-9]{1,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\._\?\,\’/\\\+&%\$#\=~-])*$”, $url)) { echo ‘URL Correct’; } else { echo ‘Bad URL’; } This will validate URL with http, https and ftp schema. 2. Using fsockopen $url = parse_url($url); $conn = fsockopen($url[‘host’], 80); if (!$conn) die(‘Cannot connect!’); fwrite($conn, “GET {$url[‘path’]} HTTP/1.0\r\nHost: {$url[‘host’]}\r\nConnection: close\r\n\r\n”); $header = fgets($conn); if (preg_match(‘|HTTP/\S+\s+[2-3]\d\d|i’, $header))…
Read More »