note 114817 added to function.parse-url
| From: | () | Date: | Wed, 09 Apr 2014 08:49:46 +0000 |
| Subject: | note 114817 added to function.parse-url | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-199232@lists.php.net to get a copy of this message | ||
Here is utf-8 compatible parse_url() replacement function based on "laszlo dot janszky at gmail
dot com" work. Original incorrectly handled URLs with user:pass. Also made PHP 5.5 compatible
(got rid of now deprecated regex /e modifier).
<?php
/**
* UTF-8 aware parse_url() replacement.
*
* @return array
*/
function mb_parse_url($url)
{
$enc_url = preg_replace_callback(
'%[^:/@?&=#]+%usD',
function ($matches)
{
return urlencode($matches[0]);
},
$url
);
$parts = parse_url($enc_url);
if($parts === false)
{
throw new \InvalidArgumentException('Malformed URL: ' . $url);
}
foreach($parts as $name => $value)
{
$parts[$name] = urldecode($value);
}
return $parts;
}
?>
----
Server IP: 212.93.98.119
Probable Submitter: 159.148.181.245
----
Manual Page -- http://php.net/manual/en/function.parse-url.php
Edit -- https://master.php.net/note/edit/114817
Del: integrated -- https://master.php.net/note/delete/114817/integrated
Del: useless -- https://master.php.net/note/delete/114817/useless
Del: bad code -- https://master.php.net/note/delete/114817/bad+code
Del: spam -- https://master.php.net/note/delete/114817/spam
Del: non-english -- https://master.php.net/note/delete/114817/non-english
Del: in docs -- https://master.php.net/note/delete/114817/in+docs
Del: other reasons-- https://master.php.net/note/delete/114817
Reject -- https://master.php.net/note/reject/114817
Search -- https://master.php.net/manage/user-notes.php