Use the PHP function parse_url to analyze information capture

Source: Internet
Author: User

  1. $ Url = "http://www.electrictoolbox.
    Com/php-extract-domain-from-full-url /";
  2. $ Parts = parse_url ($ url );

Output:

  1. Array
  2. (
  3. [Scheme] =>Http
  4. [Host] =>Www.electrictoolbox.com
  5. [Path] =>/Php-extract-
    Domain-from-full-url/
  6. )


Another example is how to use the PHP function parse_url:

 
 
  1. < ?php  
  2. $url = 'http://username:password
    @hostname/path?arg=value#anchor';  
  3. print_r(parse_url($url));  
  4. echo parse_url($url, PHP_URL_PATH);  
  5. ?> 

Output:

 
 
  1. Array  
  2. (  
  3. [scheme] => http  
  4. [host] => hostname  
  5. [user] => username  
  6. [pass] => password  
  7. [path] => /path  
  8. [query] => arg=value 
  9. [fragment] => anchor  
  10. )  

As you can see, the PHP function parse_url can easily break down all parts of a URL. It is also easy to take the specified part, as shown in figure

Echo parse_url ($ url, PHP_URL_PATH); in the second parameter, set the following parameter:

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.


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.