note 11399 added to parse_url
| From: | Tomas V . V . Cox | Date: | Mon, 19 Feb 2001 20:16:14 +0000 |
| Subject: | note 11399 added to parse_url | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11253@lists.php.net to get a copy of this message | ||
Perhaps someday you need to modify somefield from the parse_url() and then build the url again with
this data.
To make it, here I post the "glue_url" function:
// param $url is the result array from the parse_url()
function glue_url ($url){
if (!is_array($url)){
return false;
}
// scheme
$uri = (!empty($url['scheme'])) ? $url['scheme'].'://' :
'';
// user & pass
if (!empty($url['user'])){
$uri .= $url['user'].':'.$url['pass'].'@';
}
// host
$uri .= $url['host'];
// port
$port = (!empty($url['port'])) ? ':'.$url['port'] : '';
$uri .= $port;
// path
$uri .= $url['path'];
// fragment
$frag = $url['fragment'];
if (($pos = strpos($frag, '?')) !== false){
if ($pos != 0){
$anchor = '#'.substr($frag, 0, $pos);
}
$query = substr ($frag, $pos);
}
$uri .= $anchor.$query;
return $uri;
}
http://www.php.net/manual/en/function.parse-url.php