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 ?

有帮助吗?

解决方案 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.

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top