Archives for 

validity

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 […] Continue reading →