PHP正则表达式与URL解析
如何利用PHP中的PHP正则表达式与URL解析,php,parsing,Php,Parsing,如何利用PHP中的preg\u replace解析url 说我有网址 我想访问url的每个部分,这样 echo $protocol; 将打印 http google ?id=123 或 将打印 http google ?id=123 及 印刷品 com 最后 echo $rest; 将打印 http google ?id=123 从文件中 mixed parse_url ( string $url [, int $component = -1 ] ) This f
preg\u replace
解析url
说我有网址
我想访问url的每个部分,这样
echo $protocol;
将打印
http
google
?id=123
或
将打印
http
google
?id=123
及
印刷品
com
最后
echo $rest;
将打印
http
google
?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.
从文件中
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.
有一个功能: 印刷品:
Array
(
[scheme] => http
[host] => google.com
[query] => id=123
)
有一个功能: 印刷品:
Array
(
[scheme] => http
[host] => google.com
[query] => id=123
)
有一个函数用于此:@Dagon将生成一个完美的答案而不是注释:)有一个函数用于此:@Dagon将生成一个完美的答案而不是注释:)另请参见是否也要解析查询字符串。此外,如果您对分离TLD和辅助域感兴趣,您可能需要查看。还可以查看是否要解析查询字符串。此外,如果您对分离TLD和辅助域感兴趣,您可能需要查看。