Php get url parameter program code summary_php tutorial

Source: Internet
Author: User
Tags php get url
Php obtains the summary of url parameter program code. The parse_url function first describes the parse_url function. The official solution is mixedparse_url (string $ url [, int $ component-1]). This function parses a URL and returns an associated parse_url function.

Let's take a look at the parse_url function.

Description

Mixed parse_url (string $ url [, int $ component =-1])

This function parses a URL and returns an associated array, which contains various components in the URL.

This function is not used to verify the validity of a given URL, but is used to separate it into the parts listed below. Incomplete URLs are also accepted, and parse_url () tries to parse them correctly as much as possible.

The URL to be parsed. Invalid characters are replaced.

Instance

The code is as follows:

$ Url = "http://www.45it.net/welcome ";

$ Parts = parse_url ($ url );

Print_r ($ parts );


Array
(
[Scheme] => http
[Host] => www.45it.net
[Path] =>/welcome/
)

You can also write an algorithm on your own! As follows:

The code is as follows:


Function getParams ()
{
$ Url = '/index. php? _ P = index & _ a = show & x = 12 & y = 23 ';

$ Refer_url = parse_url ($ url );

$ Params = $ refer_url ['query'];

$ Arr = array ();
If (! Empty ($ params ))
{
$ ParamsArr = explode ('&', $ params );

Foreach ($ paramsArr as $ k => $ v)
{
$ A = explode ('=', $ v );
$ Arr [$ a [0] = $ a [1];
}
}
Return $ arr;
}

Call method

The code is as follows:

$ Arr = getParams ();
Print_r ($ arr );

Result

Result: Array ([_ p] => index [_ a] => show [x] => 12 [y] => 23)

For details, refer to the parse_url function. The official solution is mixed parse_url (string $ url [, int $ component =-1]). This function parses a URL and returns an association...

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.