PHP uses functions pathinfo (), Parse_url (), and basename () to parse url_php instances

Source: Internet
Author: User

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

The instance code is as follows:

1, using PathInfo to resolve the URL

?
 $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
 [filename] => index//filename
)

2. Using Parse_url () function to parse

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

The results are as follows

Array
(
 [scheme] => HTTP///using what Protocol
 [host] => localhost//host name
 [path] =>/index.php//Path
 [ Query] => name=tank&sex=1//passed parameters
 [fragment] => anchor point of Top//back root
)

3. Use basename () to resolve

?
 $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

Summarize

The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.

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.