Php uses the pathinfo (), parse_url (), and basename () functions to parse the URL, pathinfobasename

Source: Internet
Author: User

Php uses the pathinfo (), parse_url (), and basename () functions to parse the URL, pathinfobasename

This document describes how to use functions in php.pathinfo(),parse_url()Andbasename()The instance code for URL Parsing. Let's just look at the code.

The instance code is as follows:

1. Use pathinfo to parse the URL

<? $test = pathinfo("http://localhost/index.php"); print_r($test);?>

The result is as follows:

Array ([dirname] => http: // localhost // url path [basename] => index. php // complete file name [extension] => php // file name suffix [filename] => index // file name)

2. parsing using parse_url () function

<? $test = parse_url("http://localhost/index.php?name=tank&sex=1#top"); print_r($test);?>

The result is as follows:

Array ([scheme] => http // protocol used [host] => localhost // host name [path] =>/index. php // path [query] => name = tank & sex = 1 // The parameter [fragment] => top // The Anchor behind the root)

3. Use basename () for parsing

<? $test = basename("http://localhost/index.php?name=tank&sex=1#top"); echo $test;?>

The result is as follows:

index.php?name=tank&sex=1#top

Summary

The above is all about this article. I hope this article will help you in your study or work. If you have any questions, please leave a message.

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.