note 74047 deleted from function.preg-match by colder
| From: | colder@php.net | Date: | Mon, 18 Jun 2007 18:13:03 +0000 |
| Subject: | note 74047 deleted from function.preg-match by colder | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-127573@lists.php.net to get a copy of this message | ||
Note Submitter: Hayley Watson
----
RFC3986 offers a regular expression for matching URIs. Modified slightly:
<?php preg_match(
'_^(?:([^:/?#]+):)?(?://([^/?#]*))?'.
'([^?#]*)(?:\?([^#]*))?(?:#(.*))?$_',
$uri, $uri_parts); ?>
recognises anything that is a valid URI according to that specification; $uri_parts is of course an
array with the elements
[0] => the entire URI (of course)
[1] => the protocol scheme (e.g., http)
[2] => the naming authority (the entity responsible for identifying the resource)
[3] => the path
[4] => the contents of any querystring
[5] => any value of any fragment
With the example
http://www.php.net/manual/en/function.preg-match.php#id5827438
those parts are
[0] => http://www.php.net/manual/en/function.preg-match.php#id5827438
[1] => http
[2] => www.php.net
[3] => /manual/en/function.preg-match.php
[4] =>
[5] => id5827438
Of course, the parse_url() function is probably a much more legible solution - but it's amusing
to note that PHP uses over 200 lines of C to implement that function!