What regexp php is used for filter_var ($ url, FILTER_VALIDATE_URL)?

filter_var($url, FILTER_VALIDATE_URL)seems like a great way to detect if it $urlcontains a url or not. Is there a way to see which regular expression this function uses to detect?

thank

+3
source share
3 answers

It uses something else, and then a regular expression. In C, it checks the return of function php_url_parse_ex()(C), which you can see at: ext / standard / url.c, line 97 , called in ext / filter / logical_filters.c, line 440 .

: parse_url() (PHP) PHP , php_filter_validate_url() (C), .

+6

URL.

$pattern = "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i";
0

Chris' answer to the PHP regular expression for checking URLs uses parse_url, which, after reading Wrikken's answer about what filter_var actually does ($ url, FILTER_VALIDATE_URL), seems to be the best because it allows you to control the majority.

0
source

Source: https://habr.com/ru/post/1755936/


All Articles