note 83828 added to function.parse-url
| From: | to1ne at hotmail dot com | Date: | Fri, 13 Jun 2008 18:01:45 +0000 |
| Subject: | note 83828 added to function.parse-url | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140418@lists.php.net to get a copy of this message | ||
Based on the idea of "jbr at ya-right dot com" have I been working on a new function to
parse the url:
<?php
function parseUrl($url) {
$r = "^(?:(?P<scheme>\w+)://)?";
$r .= "(?:(?P<login>\w+):(?P<pass>\w+)@)?";
$r .= "(?P<host>(?:(?P<subdomain>[\w\.]+)\.)?" .
"(?P<domain>\w+\.(?P<extension>\w+)))";
$r .= "(?::(?P<port>\d+))?";
$r .= "(?P<path>[\w/]*/(?P<file>\w+(?:\.\w+)?)?)?";
$r .= "(?:\?(?P<arg>[\w=&]+))?";
$r .= "(?:#(?P<anchor>\w+))?";
$r = "!$r!"; // Delimiters
preg_match ( $r, $url, $out );
return $out;
}
print_r ( parseUrl (
'me:you@sub.site.org:29000/pear/validate.html?happy=me&sad=you#url' ) );
?>
This returns:
Array
(
[0] => me:you@sub.site.org:29000/pear/validate.html?happy=me&sad=you#url
[scheme] =>
[1] =>
[login] => me
[2] => me
[pass] => you
[3] => you
[host] => sub.site.org
[4] => sub.site.org
[subdomain] => sub
[5] => sub
[domain] => site.org
[6] => site.org
[extension] => org
[7] => org
[port] => 29000
[8] => 29000
[path] => /pear/validate.html
[9] => /pear/validate.html
[file] => validate.html
[10] => validate.html
[arg] => happy=me&sad=you
[11] => happy=me&sad=you
[anchor] => url
[12] => url
)
So both named and numbered array keys are possible.
It's quite advanced, but I think it works in any case... Let me know if it doesn't...
----
Server IP: 193.190.67.16
Probable Submitter: 81.164.55.3
----
Manual Page -- http://www.php.net/manual/en/function.parse-url.php
Edit -- https://master.php.net/note/edit/83828
Del: integrated -- https://master.php.net/note/delete/83828/integrated
Del: useless -- https://master.php.net/note/delete/83828/useless
Del: bad code -- https://master.php.net/note/delete/83828/bad+code
Del: spam -- https://master.php.net/note/delete/83828/spam
Del: non-english -- https://master.php.net/note/delete/83828/non-english
Del: in docs -- https://master.php.net/note/delete/83828/in+docs
Del: other reasons-- https://master.php.net/note/delete/83828
Reject -- https://master.php.net/note/reject/83828
Search -- https://master.php.net/manage/user-notes.php