Url几个常用的函数
parse_url()
本函数不是用来验证给定 URL 的合法性的,只是将其分解为下面列出的部分。不完整的 URL 也被接受, parse_url() 会尝试尽量正确地将其解析。
1 | <span style= "color: #800080;" > $_url </span> = "http://www.baidu.com/web?id=15&page=5" <span style= "color: #000000;" >; $_par = pares_url( $_url ); </span><span style= "color: #008080;" >var_dump</span>( $_par );<br><br>输出结果:
|
Nach dem Login kopieren
1 | <span style= "color: #0000ff;" > array </span>(4<span style= "color: #000000;" >) { [</span> "scheme" ]=> <span style= "color: #0000ff;" >string</span>(4) "http" <span style= "color: #000000;" > [</span> "host" ]=> <span style= "color: #0000ff;" >string</span>(13) "www.baidu.com" <span style= "color: #000000;" > [</span> "path" ]=> <span style= "color: #0000ff;" >string</span>(4) "/web" <span style= "color: #000000;" > [</span> "query" ]=> <span style= "color: #0000ff;" >string</span>(12) "id=15&page=5" <span style= "color: #000000;" >}</span>
|
Nach dem Login kopieren
parse_str()
将字符串解析成多个变量
1 | <span style= "color: #008080;" > parse_str </span>(<span style= "color: #800080;" > $_par </span>[ 'query' ],<span style= "color: #800080;" > $_query </span><span style= "color: #000000;" >); </span><span style= "color: #008080;" >var_dump</span>(<span style= "color: #800080;" > $_query </span><span style= "color: #000000;" >);输出结果:</span><span style= "color: #0000ff;" > array </span>(2<span style= "color: #000000;" >) { [</span> "id" ]=> <span style= "color: #0000ff;" >string</span>(2) "15" <span style= "color: #000000;" > [</span> "page" ]=> <span style= "color: #0000ff;" >string</span>(1) "5" <span style= "color: #000000;" >}</span>
|
Nach dem Login kopieren
http_bulid_query()
使用给出的关联(或下标)数组生成一个经过 URL-encode 的请求字符串。
1 | <span style= "color: #0000ff;" >unset</span>(<span style= "color: #800080;" > $_query </span>[ 'page' ]); <span style= "color: #008000;" >
|
Nach dem Login kopieren
用于解析、拆分、重组URL字符串。