Heim > php教程 > php手册 > Hauptteil

php提取URL中的域名部分

WBOY
Freigeben: 2016-06-06 20:08:41
Original
1879 Leute haben es durchsucht

今天写小东西,有个需求,提取整个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'));
?>
Nach dem Login kopieren

运行结果:


Array
(
    [scheme] => http
    [host] => wdot.cc
    [path] => /Attack/90.html
)
Nach dem Login kopieren

函数说明:

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.

Verwandte Etiketten:
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Empfehlungen
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!