php 带http的域名,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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值