note 82948 added to function.parse-url
| From: | jbr at ya-right dot com | Date: | Sat, 03 May 2008 03:24:27 +0000 |
| Subject: | note 82948 added to function.parse-url | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139015@lists.php.net to get a copy of this message | ||
This function never works the way you think it should...
Example....
<?php
print_r ( parse_url ( 'me:you@sub.site.org/pear/validate.html?happy=me&sad=you#url' )
);
?>
Returns...
Array
(
[scheme] => me
[path] => you@sub.site.org/pear/validate.html
[query] => happy=me&sad=you
[fragment] => url
)
Here my way of doing parse_url
<?php
function parseUrl ( $url )
{
$r = '!(?:(\w+)://)?(?:(\w+)\:(\w+)@)?([^/:]+)?';
$r .= '(?:\:(\d*))?([^#?]+)?(?:\?([^#]+))?(?:#(.+$))?!i';
preg_match ( $r, $url, $out );
return $out;
}
print_r ( parseUrl ( 'me:you@sub.site.org/pear/validate.html?happy=me&sad=you#url' )
);
?>
Returns...
Array
(
[0] => me:you@sub.site.org/pear/validate.html?happy=me&sad=you#url
[1] =>
[2] => me
[3] => you
[4] => sub.site.org
[5] =>
[6] => /pear/validate.html
[7] => happy=me&sad=you
[8] => url
)
Where as...
out[0] = full url
out[1] = scheme or '' if no scheme was found
out[2] = username or '' if no auth username was found
out[3] = password or '' if no auth password was found
out[4] = domain name or '' if no domain name was found
out[5] = port number or '' if no port number was found
out[6] = path or '' if no path was found
out[7] = query or '' if no query was found
out[8] = fragment or '' if no fragment was found
----
Server IP: 69.147.83.197
Probable Submitter: 71.233.50.85
----
Manual Page -- http://www.php.net/manual/en/function.parse-url.php
Edit -- https://master.php.net/note/edit/82948
Del: integrated -- https://master.php.net/note/delete/82948/integrated
Del: useless -- https://master.php.net/note/delete/82948/useless
Del: bad code -- https://master.php.net/note/delete/82948/bad+code
Del: spam -- https://master.php.net/note/delete/82948/spam
Del: non-english -- https://master.php.net/note/delete/82948/non-english
Del: in docs -- https://master.php.net/note/delete/82948/in+docs
Del: other reasons-- https://master.php.net/note/delete/82948
Reject -- https://master.php.net/note/reject/82948
Search -- https://master.php.net/manage/user-notes.php