Php extracts the domain name from the URL

Source: Internet
Author: User
Today, I wrote a little thing. I have a requirement to extract the Domain Name of the whole URL. I used EasyXSS before. What is a function? I am too lazy to translate the source code. Then I googled it. Sure enough, search for keywords, truncation of strings, and so on... Is it so troublesome .. So record it here .? PhpWdotwdot. ccprin

Today, I wrote a little thing. I have a requirement to extract the Domain Name of the whole URL. I used EasyXSS before. What is a function? I am too lazy to translate the source code. Then I googled it. Sure enough, search for keywords, truncation of strings, and so on... Is it so troublesome .. So record it here. ? Php // Wdot http://wdot.ccprin

Today, I wrote a little thing. I have a requirement to extract the Domain Name of the whole URL. I used EasyXSS before. What is a function? I am too lazy to translate the source code. Then I googled it. Sure enough, search for keywords, truncation of strings, and so on... Is it so troublesome .. So record it here.


 

Running result:


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

Function Description:

Parse_url

(PHP 4, PHP 5)

Parse_url-Parse a URL and return its components

Description

MixedParse_url(String $ url [, int $ component=-1])

This function parses a URL and returns an associative array containing any of the varous components of the URL that are present.

This function isNotMeant 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_.

Component

Specify one of clusters, PHP_URL_HOST, PHP_URL_PORT, PHP_URL_USER, PHP_URL_PASS, PHP_URL_PATH, PHP_URL_QUERY or resume to retrieve just a specific URL component as a string (Response t when provided 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.

Original article address: php extracts the domain name from the URL and thanks to the original author for sharing it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.