PHP uses functions pathinfo (), Parse_url (), and basename () to resolve URLs

Source: Internet
Author: User
It is well known that in PHP functions PathInfo (), Parse_url (), and basename (), these three are the functions that parse the URL, but there are some differences, here are some examples, it is easier to understand the use of these three functions using methods and techniques, Friends who need to be able to reference, interested in the following friends to learn together.

This article mainly introduces the PHP use of functions pathinfo() , parse_url() and basename() parse the URL of the instance code, the following words do not say, directly to see the code

The instance code is as follows:

1. Using PathInfo to parse URLs

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

The results are as follows

Array ([dirname] = http://localhost//url path [basename] = index.php//full file name [extension] + PHP//filename suffix [filenam E] = = index//file name)

2, using Parse_url () function analysis

<? $test = Parse_url ("Http://localhost/index.php?name=tank&sex=1#top"); Print_r ($test);? >

The results are as follows

Array ([scheme] + HTTP//Use what protocol [host] + localhost//hostname [path] +/index.php//path [query] = name=tank& Sex=1//transmitted parameters [fragment] = Top//anchor point of the back root)

3, using basename () analysis

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

The results are as follows

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

The above is the whole content of this article, I hope that everyone's study has helped.


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.