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.