preg_replace
URLを解析するためにPHPでどのように利用できますか 。
URLを持っているとしましょう
そして、そのようなURLの各部分にアクセスしたい
echo $protocol;
印刷します
http
また
echo $domain;
印刷します
google
と
echo $upperDomain;
版画
com
そして最後に、
echo $rest;
印刷します
?id=123
preg_replace
URLを解析するためにPHPでどのように利用できますか 。
URLを持っているとしましょう
そして、そのようなURLの各部分にアクセスしたい
echo $protocol;
印刷します
http
また
echo $domain;
印刷します
google
と
echo $upperDomain;
版画
com
そして最後に、
echo $rest;
印刷します
?id=123
そのための関数があります: parse_url()
$url = 'http://google.com?id=123';
print_r(parse_url($url));
プリント:
Array
(
[scheme] => http
[host] => google.com
[query] => id=123
)
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.