Etienne Kneuss

home » repository » php » sample » regex_urls.php
Tree:
school
mp3
php
sample
sort.php
bitmask.php
disable_magic_quotes.php
BB.php
regex_urls.php
highlight_patch.php
publications
Math_Derivative
Math_Expression
ircbot
php.net
images
dump

Source code raw phps

    <?php /**  * This regex matches compliant URL  * rfcs: http://www.ietf.org/rfc/rfc1738.txt  *       http://www.ietf.org/rfc/rfc1808.txt  */ $regex = '#https?://(?P<host>[a-z](?:[a-z0-9-]*[a-z0-9])?(?:\.[a-z](?:[a-z0-9'.          '-]*[a-z0-9]))*)(?P<port>:\d+)?(?:/(?P<path>(?:[a-zA-Z0-9$_.+!*\'(),'.          ';:@&=-]|&[0-9a-f]{2})+(?:/(?:[a-zA-Z0-9$_.+!*\'(),;:@&=-]|&[0-9a-f]'.          '{2})*)*)?(?:\?(?P<querystring>(?:[a-zA-Z0-9$_.+!*\'(),;:@&=/-]|&[0-'.          '9a-f]{2})*))?)?(?:\#(?P<fragment>[a-zA-Z0-9$_.+!*\'(),;:@&=/-]|&[0-'.          '9a-f]{2})*)?#'; $urls = <<<URLS https://foo.bar.com.eu:8080/ http://localhost:8081/file.php http://localhost/file.php?querystring&path=/foo/bar http://localhost/path/to/file.php?querystring&path=/foo/bar#fragment URLS; echo preg_match_all($regex, $urls, $matches); // 4

Comments

There is currently no comment here.

Add a comment

Username:

Spam Challenge: 3+14=?

Comment: