Everything that starts with http: // is checked by FILTER_VALIDATE_URL?

I tested the lines and int that I can imagine, as long as it starts with http: //, this will be a valid URL using FILTER_VALIDATE_URL. So why do we need FILTER_VALIDATE_URL? Why not just add http: // on the tab whenever we want to make it valid?

var_dump(filter_var ('http://example',FILTER_VALIDATE_URL ));
+5
source share
1 answer

Well, technically, any URI that starts with a scheme (for example http://) and contains valid URI characters after it is valid according to the official URI specification in RFC 3986 :

URI , 3.1, . , URI , .

, , , - , . filter_var FILTER_VALIDATE_URL... , - URL, ?

if (strpos($url, 'http://') === 0
    || strpos($url, 'ftp://') === 0
    || strpos($url, 'telnet://') === 0
) {
    // it a valid URL!
}
+10

All Articles