URL can simply validate use FILTER_VALIDATE_URL in filter_var().
For example:
$url = "http://www.php.net"; /*** try to validate the URL ***/ if(filter_var($url, FILTER_VALIDATE_URL) === FALSE) { /*** if there is no match ***/ echo "Sorry, $url is not valid!"; } else { /*** if we match the pattern ***/ echo "The URL, $url is valid!<br />"; }
IT can be in a function:
function validate_url($url) { if(filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED) === FALSE) { /*** if there is no match ***/ return false; } else { /*** if the URL is valid ***/ return true; } }
What do you think?