php - validate URL by FILTER_VALIDATE_URL -
php - validate URL by FILTER_VALIDATE_URL -
i validating url filter_validate_url
function.
$url_1 = "http://example.com"; $url_2 = "http://http://example.com"; if (filter_var($url_1, filter_validate_url)) { echo "url valid"; } else { echo "url invalid"; }
it's giving me valid url message in $url_1
, $url_2
. shouldn't that. sec url not valid. what's right way solve issue? thanks.
as per docs on validation filters, filter_validate_url
validate url rfc 2396 standards.
there's been give-and-take on examples still pass filter_validate_url
filter.
this means can utilize filter some validation, can't depend on solely if need 100% valid url conditions still satisfy rfc, plus valid url still homecoming 404
.
your best approach test valid url test url after validating as per answer
php validation
Comments
Post a Comment