Parse URL instance using PHP pathinfo (), Parse_url (), basename () function

Source: Internet
Author: User
PHP functions PathInfo (), Parse_url (), and basename (), these three are all functions that parse the URL, but there are some differences, this article lists some examples, hope that through these examples to help you understand the three functions of the use of methods and techniques, Take a look at it:

1. Using PathInfo to parse URLs

The PathInfo function is the path, directory, or file name that gets the file.

example, the code is as follows

< $test = PathInfo ("http://www.php.cn/index.php");p Rint_r ($test); >

Code Run Result:

2, using Parse_url () function analysis

The Parse_url () function is used to parse the URL and return an associative array of parsing components, which does not detect whether the URL is legitimate and only resolves it as correctly as possible.

example, the code is as follows

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

Code Run Result:

3, using basename () analysis

The basename () function returns the file name in the path

example, the code is as follows

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

Code Run Result:

"Related articles recommended":

1. Detailed php pathinfo () function get file path information

2. The PHP basename () function Gets the use of the file name

3. A detailed description of PHP parse_url () function definition and usage

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.