Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

regex

php

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

like image 856
Kirzilla Avatar asked Mar 07 '26 00:03

Kirzilla


1 Answers

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.

like image 113
Wrikken Avatar answered Mar 08 '26 13:03

Wrikken



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!