Why is filter_var with FILTER_VALIDATE_URL showing this string as a valid URL?

The input string is:

https://lh

however, with:

var_dump(filter_var('https://lh', FILTER_VALIDATE_URL)) // string(10) "https://lh"

for some reason the above string is classed as a valid URL. I have read another SO post saying that FILTER_VALIDATE_URL is not restricted to the http protocol but surely the above link is not a valid URL for any protocol.

Why is this happening?

728x90

1 Answers Why is filter_var with FILTER_VALIDATE_URL showing this string as a valid URL?

OK, so lots of comments later with some digression and no posted answer.

Therefore...

A valid URL doesn't have to use a FQDN - it can use just a host name. protocol://host:port/path/filename.foo?arguments Protocol and host name are the only things required to initiate a connection, only critical part on the host name is that the client has to be able to resolve it - hosts file, dns, dns with appended search domain(s), etc

If any of the other commenters feel the need to edit, etc. feel free.

4 months ago