摘要:本文主要介紹的是php使用函數(shù)pathinfo() 、parse_url()和basename()解析URL的實例代碼,下面話不多說,直接來看代碼實例代碼如下:1、利用pathinfo解析URL<? $test = pathinfo("http://localhost/index.php"); print_r($tes
本文主要介紹的是php使用函數(shù)pathinfo() 、parse_url()和basename()解析URL的實例代碼,下面話不多說,直接來看代碼
實例代碼如下:
1、利用pathinfo解析URL
<? $test = pathinfo("http://localhost/index.php"); print_r($test); ?>
結(jié)果如下
Array ( [dirname] => http://localhost //url的路徑 [basename] => index.php //完整文件名 [extension] => php //文件名后綴 [filename] => index //文件名 )
2、利用parse_url()函數(shù)解析
<? $test = parse_url("http://localhost/index.php?name=tank&sex=1#top"); print_r($test); ?>
結(jié)果如下
Array ( [scheme] => http //使用什么協(xié)議 [host] => localhost //主機名 [path] => /index.php //路徑 [query] => name=tank&sex=1 // 所傳的參數(shù) [fragment] => top //后面根的錨點 )
3、使用basename()解析
<? $test = basename("http://localhost/index.php?name=tank&sex=1#top"); echo $test; ?>
結(jié)果如下
index.php?name=tank&sex=1#top
總結(jié)
以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作能帶來一定的幫助,如果有疑問大家可以留言交流。
更多關(guān)于php使用函數(shù)pathinfo()、parse_url()和basename()解析URL請關(guān)注PHP中文網(wǎng)(www.miracleart.cn)其它文章!