0

preg_replaceURLを解析するためにPHPでどのように利用できますか 。

URLを持っているとしましょう

http://google.com?id=123

そして、そのようなURLの各部分にアクセスしたい

echo $protocol;

印刷します

http

また

echo $domain;

印刷します

google

echo $upperDomain;

版画

com

そして最後に、

echo $rest;

印刷します

?id=123
4

2 に答える 2

4

そのための関数があります: parse_url()

$url = 'http://google.com?id=123';    
print_r(parse_url($url));

プリント:

Array
(
    [scheme] => http
    [host] => google.com
    [query] => id=123
)
于 2012-12-18T23:47:55.567 に答える
0

ドキュメントからparse_url() ...

 mixed parse_url ( string $url [, int $component = -1 ] )

This function parses a URL and returns an associative array containing any of the   
various components of the URL that are present.

This function is not meant to validate the given URL, it only breaks it up into the 
above listed parts. Partial URLs are also accepted, parse_url() tries its best to   
parse them correctly. 
于 2012-12-18T23:47:32.983 に答える