(PECL pecl_http >= 0.21.0)
http_build_url — 产生一个 URL
$url
[, mixed $parts
[, int $flags
= HTTP_URL_REPLACE
[, array &$new_url
]]]] )产生一个 URL。
第二个 URL 的组成部分将根据 flags 参数,合并到第一个 URL。
url
一个或多个 URL 的组成部分字符串,或类似 parse_url() 所返回的关联数组。
parts
和第一个参数一样。
flags
HTTP_URL 常量的二进制或运算位掩码;默认是 HTTP_URL_REPLACE
。
new_url
如果设置了,它将被 URL 组成部分所填充,就像 parse_url() 所返回的那样
成功时返回新的 URL, 或者在失败时返回 FALSE
。
Example #1 http_build_url() 的一个例子
<?php
echo http_build_url("http://user@www.example.com/pub/index.php?a=b#files",
array(
"scheme" => "ftp",
"host" => "ftp.example.com",
"path" => "files/current/",
"query" => "a=c"
),
HTTP_URL_STRIP_AUTH | HTTP_URL_JOIN_PATH | HTTP_URL_JOIN_QUERY | HTTP_URL_STRIP_FRAGMENT
);
?>
以上例程会输出:
ftp://ftp.example.com/pub/files/current/?a=c
randyg at ernieball dot com (2012-02-06 20:15:14)
Although I've never used this function, based on the documentation it seems that the above code should also include the following:
<?php
if ( ! is_array( $url ) ) // Added - Randy
// Parse the original URL
$parse_url = parse_url($url);
// allow parts to be a url Added - Randy
if ( ! is_array( $parts ) )
$parts = parse_url( $parts );
?>
Ant P. (2010-06-09 09:58:49)
This function has a useful undocumented feature - the defaults are set in such a way that calling it with no parameters returns the full URL of the page being accessed.