时间:2021-07-01 10:21:17 帮助过:8人阅读
function modify_build_url($params = array(), $url = NULL) {
//my_debug(current_url());
if (! $url) {
$url = $_SERVER ['REQUEST_URI'];
}
$parts = parse_url ( $url );
if (! is_array ( $parts )) {
$parts = array ();
}
if (! array_key_exists ( 'host', $parts )) {
$parts ['host'] = $_SERVER ['HTTP_HOST'];
}
$gets = array ();
if (array_key_exists ( 'query', $parts )) {
$query = $parts ['query'];
parse_str ( $query, $gets );
}
if (! is_array ( $params )) {
$params = array ();
}
if (! is_array ( $gets )) {
$gets = array ();
}
foreach ( $params as $k => $v ) {
$gets [$k] = $v;
}
$path = null;
if (array_key_exists ( 'path', $parts )) {
$path = $parts ['path'];
}
if (! $path) {
$path = "/";
}
$ret = sprintf ( "http://%s%s?%s", $parts ['host'], $path, http_build_query ( $gets ) );
return $ret;
}