Question

if (!filter_var($site, FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED))...

This validator shows:
https://www.g - as valid address !
www.google.com - as invalid address !

If you type some address into address bar, and you see that it works - it should be a valid address. And vice versa. I need such one validator. Or - I'm missing something in the above code ?

Was it helpful?

Solution 2

A user comment on php.net states:

"Please note that FILTER_FLAG_HOST_REQUIRED and FILTER_FLAG_SCHEME_REQUIRED have disappeared. They were previously mentioned in the constants page but it seems that host and scheme are now required by default for the validate_url filter."

Seems like the protocol is a must with recent PHP versions and cannot be disabled.

OTHER TIPS

www.google.com is not a valid url. It needs a protocol for it to be valid i.e. http://www.google.com

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top