示例
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';print_r(parse_url($url));
?>结果
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)相关函数
string http_build_url ([ mixed $url [, mixed $parts [, int $flags = HTTP_URL_REPLACE [, array &$new_url ]]]] )示例
<?php
echo http_build_url("http://[email protected]/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=b&a=c
<?php
$url = 'http://username:password@hostname/path?arg=value#anchor';print_r(parse_url($url));
?>结果
Array
(
[scheme] => http
[host] => hostname
[user] => username
[pass] => password
[path] => /path
[query] => arg=value
[fragment] => anchor
)相关函数
string http_build_url ([ mixed $url [, mixed $parts [, int $flags = HTTP_URL_REPLACE [, array &$new_url ]]]] )示例
<?php
echo http_build_url("http://[email protected]/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=b&a=c
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货