简体   繁体   中英

Which regexp php is using for filter_var($url, FILTER_VALIDATE_URL)?

filter_var($url, FILTER_VALIDATE_URL) seems to be great way to detect if $url contains url or not. Is there any way to see what regular expression this function uses for detecting?

Thank you

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

In these terms: if you call parse_url() (PHP) in PHP, and perform the same checks as in php_filter_validate_url() (C), you'd have the same output.

该模式类似于 URL 解析。

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

Kris在PHP正则表达式中用于验证URL的答案使用了parse_url,在阅读Wrikken关于filter_var($ url,FILTER_VALIDATE_URL)实际执行的操作的答案之后,这似乎是最好的,因为它允许最大程度的控制。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM