首页 > php教程 > php手册 > 正文

php提取URL中的域名部分

php中文网
发布: 2016-06-06 20:08:41
原创
2227人浏览过

今天写小东西,有个需求,提取整个url的域名部分,以前写easyxss时用过,一个什么函数来着,懒得翻源码,随即google了一下,果然, 找到的都是查找关键字、截断字符串之类的做法。。。用得着那么麻烦么。。所以在此记录一下。 ?php//Wdot http://wdot.ccprin

今天写小东西,有个需求,提取整个url的域名部分,以前写easyxss时用过,一个什么函数来着,懒得翻源码,随即google了一下,果然, 找到的都是查找关键字、截断字符串之类的做法。。。用得着那么麻烦么。。所以在此记录一下。


<?php
//Wdot http://wdot.cc
print_r(parse_url('http://wdot.cc/Attack/90.html'));
?>
登录后复制

运行结果:


Array
(
    [scheme] => http
    [host] => wdot.cc
    [path] => /Attack/90.html
)
登录后复制

函数说明:

多个微信小程序源码合集
多个微信小程序源码合集

微信小程序是一种轻量级的应用开发平台,由腾讯公司推出,主要应用于移动端,旨在提供便捷的用户体验,无需下载安装即可在微信内使用。本压缩包包含了丰富的源码资源,涵盖了多个领域的应用场景,下面将逐一介绍其中涉及的知识点。1. 图片展示:这部分源码可能涉及了微信小程序中的``组件的使用,用于显示图片,以及`wx.getSystemInfo`接口获取屏幕尺寸,实现图片的适配和响应式布局。可能还包括了图片懒加

多个微信小程序源码合集 0
查看详情 多个微信小程序源码合集

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
PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号