I tested with strings and int that I can imagine, as long as it start with http://, it will be a valid url using FILTER_VALIDATE_URL. So, why we need FILTER_VALIDATE_URL? Why not just add http:// on an input whenever we want to make it valid?
var_dump(filter_var ('http://example',FILTER_VALIDATE_URL ));
Well technically, any URI that starts with a scheme (like
http://
) and contains valid URI characters after that is valid as per the official URI specification in RFC 3986:So there's nothing strange about the return you're getting -- that's what's supposed to happen. As to why you should use the
filter_var
with theFILTER_VALIDATE_URL
flag ... it's way more semantically appropriate than doing something like the following for every possible URL scheme, wouldn't you agree?