note 74047 added to function.preg-match

From: Date: Wed, 21 Mar 2007 23:19:02 +0000
Subject: note 74047 added to function.preg-match
Groups: php.notes 
Request: Send a blank email to php-notes+get-124692@lists.php.net to get a copy of this message
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! ---- Server IP: 203.89.181.184 Probable Submitter: 60.234.168.92 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match.php Edit -- https://master.php.net/note/edit/74047 Del: integrated -- https://master.php.net/note/delete/74047/integrated Del: useless -- https://master.php.net/note/delete/74047/useless Del: bad code -- https://master.php.net/note/delete/74047/bad+code Del: spam -- https://master.php.net/note/delete/74047/spam Del: non-english -- https://master.php.net/note/delete/74047/non-english Del: in docs -- https://master.php.net/note/delete/74047/in+docs Del: other reasons-- https://master.php.net/note/delete/74047 Reject -- https://master.php.net/note/reject/74047 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124692) next »