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?
filter_var($url, FILTER_VALIDATE_URL)
$url
thank
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 .
php_url_parse_ex()
: parse_url() (PHP) PHP , php_filter_validate_url() (C), .
parse_url()
php_filter_validate_url()
URL.
$pattern = "/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i";
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.
Source: https://habr.com/ru/post/1755936/More articles:Implementing Fieldset on Symfony Forms - phpC ++ function call from C # - unbalanced stack - c ++How to combine CSV files in Java - javaConstantly delayed job queue for Java - javaBringing unit testing to an existing project - javaCustom WPF TextBlock packaging: left and after "." - trimCustom overlay on Google Map? - iphoneUsing type parameters and mixins in Scala - scalaNSPredicate - not working as expected - iphoneLinks ALL Properties MsBuild - scriptingAll Articles