note 83875 added to function.parse-url
| From: | laulibrius at hotmail dot com | Date: | Mon, 16 Jun 2008 16:31:48 +0000 |
| Subject: | note 83875 added to function.parse-url | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-140506@lists.php.net to get a copy of this message | ||
There was one thing missing in the function dropped by "to1ne at hotmail dot com" when i
tried it : domain and subdomain couldn't have a dash "-". So i add it in the regexp
and the function looks like this now :
<?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;
}
?>
Btw, thanks for the function, it helps me a lot.
----
Server IP: 213.246.42.8
Probable Submitter: 82.249.115.119
----
Manual Page -- http://www.php.net/manual/en/function.parse-url.php
Edit -- https://master.php.net/note/edit/83875
Del: integrated -- https://master.php.net/note/delete/83875/integrated
Del: useless -- https://master.php.net/note/delete/83875/useless
Del: bad code -- https://master.php.net/note/delete/83875/bad+code
Del: spam -- https://master.php.net/note/delete/83875/spam
Del: non-english -- https://master.php.net/note/delete/83875/non-english
Del: in docs -- https://master.php.net/note/delete/83875/in+docs
Del: other reasons-- https://master.php.net/note/delete/83875
Reject -- https://master.php.net/note/reject/83875
Search -- https://master.php.net/manage/user-notes.php