I found this great piece of code for validating URL's. I've been trying to get it to work with preg_match() since eregi() is deprecated with with PHP 5.3:
// SCHEME
$urlregex = "^(https?|ftp)://";
// USER AND PASS (optional)
$urlregex .= "([a-z0-9+!*(),;?&=$_.-]+(:[a-z0-9+!*(),;?&=$_.-]+)?@)?";
// HOSTNAME OR IP
$urlregex .= "[a-z0-9+$_-]+(.[a-z0-9+$_-]+)*"; // http://x = allowed (ex. http://localhost, http://routerlogin)
//$urlregex .= "[a-z0-9+$_-]+(.[a-z0-9+$_-]+)+"; // http://x.x = minimum
//$urlregex .= "([a-z0-9+$_-]+.)*[a-z0-9+$_-]{2,3}"; // http://x.xx(x) = minimum
//use only one of the above
// PORT (optional)
$urlregex .= "(:[0-9]{2,5})?";
// PATH (optional)
$urlregex .= "(/([a-z0-9+$_-].?)+)*/?";
// GET Query (optional)
$urlregex .= "(?[a-z+&$_.-][a-z0-9;:@/&%=+$_.-]*)?";
// ANCHOR (optional)
$urlregex .= "(#[a-z_.-][a-z0-9+$_.-]*)?$";
// check
if (eregi($urlregex, $url)) {echo "good";} else {echo "bad";}
The problem seems to be that this is POSIX and for preg it needs to be PCRE. I'm having quite a time with it. Anyone know how to fix it?