[英]PHP regular expression and URL parsing
如何使用PHP中的preg_replace
來解析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
)
來自文檔的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.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.