PHP中URL分析函数:parse_url

有这样一个地址:$url = 'http://www.goalercn.com:8080/tech/view.php?id=111&sortid=222#mark=333';
分析这个URL,可以使用parse_url
执行如下代码:

 

$url   =   ' http://www.goalercn.com:8080/tech/download.asp?id=111&sortid=222#mark=333 ' ;
$url_info = parse_url ( $url );
echo   $url_info ;

 

返回一个数组,详细的是:
Array ([scheme] => http [host] => www.goalercn.com [port] => 8080 [path] => /tech/view.php [query] => id=111&sortid=222 [fragment] => mark=333)

执行如下代码:

echo $url_info['host'].'


';
echo $url_info['port'].'
';
echo $url_info['path'].'
';
echo $url_info['query'].'
';
echo $url_info['fragment'];

返回:
www.goalercn.com
--------------------------------------------------------------------------------
8080
--------------------------------------------------------------------------------
/tech/view.php
--------------------------------------------------------------------------------
id=111&sortid=222
--------------------------------------------------------------------------------
mark=333

下来的事,想怎么使用就怎么使用吧。。。
本文转自[Goaler's BLOG]:http://blog.goalercn.com/blogview.asp?logID=460

你可能感兴趣的:(url,php,scheme,query,path,blog)