I\'ve been reading various posts on Stack Overflow to try and find an ideal way to validate a URL in PHP. My research has come up with three possible solutions, however, no
How about you combine filter_var
(which basically is a regex check that spans pages) with additional regex check for cases you don't think are covered well by it?
I ussually use parse_url()
for check/validate url (in most case, i need to determine whether the url is already a valid url or a relative url)
if (parse_url($url, PHP_URL_SCHEME) != '')
{
// Url is absolute
}
else
{
// Url is not an absolute url, and therefore, need more validation...
}