Php uses the pathinfo (), parse_url (), and basename () functions to parse the URL_php instance.

Source: Internet
Author: User
We all know that the pathinfo (), parse_url (), and basename () functions in PHP are URL-resolved functions, but there are also some differences. The following lists some examples, through examples, it is easier to understand the usage methods and skills of these three functions. if you need them, you can refer to them. if you are interested, let's study them together. This document describes how to use functions in php. pathinfo(), parse_url()And basename()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.

Related Article

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.