php提取URL中的域名部分
今天写小东西,有个需求,提取整个URL的域名部分,以前写EasyXSS时用过,一个什么函数来着,懒得翻源码,随即google了一下,果然, 找到的都是查找关键字、截断字符串之类的做法。。。用得着那么麻烦么。。所以在此记录一下。 ?php//Wdot http://wdot.ccprin
今天写小东西,有个需求,提取整个URL的域名部分,以前写EasyXSS时用过,一个什么函数来着,懒得翻源码,随即google了一下,果然, 找到的都是查找关键字、截断字符串之类的做法。。。用得着那么麻烦么。。所以在此记录一下。
运行结果:
Array ( [scheme] => http [host] => wdot.cc [path] => /Attack/90.html )
函数说明:
parse_url
(PHP 4, PHP 5)
parse_url — Parse a URL and return its components
Description
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.
Parameters
url
The URL to parse. Invalid characters are replaced by _.
component
Specify one of PHP_URL_SCHEME, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or PHP_URL_FRAGMENT to retrieve just a specific URL component as a string (except when PHP_URL_PORT is given, in which case the return value will be an integer).
Return Values
On seriously malformed URLs, parse_url() may return FALSE.
If the component parameter is omitted, an associative array is returned. At least one element will be present within the array. Potential keys within this array are:
- scheme - e.g. http
- host
- port
- user
- pass
- path
- query - after the question mark ?
- fragment - after the hashmark #
If the component parameter is specified, parse_url() returns a string (or an integer, in the case of PHP_URL_PORT) instead of an array. If the requested component doesn't exist within the given URL, NULL will be returned.
原文地址:php提取URL中的域名部分, 感谢原作者分享。
上一篇: mysql sharding(碎片)介绍
下一篇: mysql 并发插入简单测试
推荐阅读
-
PHP实现把文本中的URL转换为链接的auolink()函数分享_PHP
-
php 提取身份证号码中的生日以及确定是否未成年人的一个函数
-
thinkphp 如何去除url中的index.php
-
PHP实现把文本中的URL转换为链接的函数
-
PHP解析URL并得到URL中的参数_PHP教程
-
php如何把网页中的一部分生成.jpg
-
php 中require和include引用url和 php的文件编码转换函数问题
-
php正则表达式 获取开始字符串和结束字符串中的部分内容
-
php进行支付宝开发中return_url和notify_url的区别分析,支付宝notifyurl_PHP教程
-
php 中require和include引用url和 php的文件编码转换函数问题_PHP教程