PHP get URL parameter method summary, PHP get URL parameter _php tutorial

Source: Internet
Author: User
Tags php get url

PHP get URL parameter method summary, PHP get URL parameter


The example in this article describes how PHP gets URL parameters. Share to everyone for your reference. Specific as follows:

In PHP, there are many ways to get the parameters in the URL, the simplest of which is to use the Parse_url function directly, he can easily and quickly automatically parse the URL parameters and values and save to the corresponding array, the other method is basically a regular expression to operate.

Parse_url function
Let's take a look at the Parse_url function, the official solution

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

This function parses a URL and returns an associative array containing the various components that appear in the URL.
This function is not used to validate the legitimacy of a given URL, but to decompose it into the parts listed below. An incomplete URL is also accepted, and Parse_url () tries to parse it as correctly as possible.
The URL to resolve. Invalid characters will be replaced with _.

Examples are as follows:
Copy the Code code as follows: $url = "http://www.bkjia.com/welcome/";
$parts = Parse_url ($url);
Print_r ($parts);

Array
(
[Scheme] = http
[Host] = Www.jb51.net
[Path] =/welcome/
)
You can also write an algorithm yourself!
Copy the Code code 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;
}
Calling methods
Copy the Code code as follows: $arr = Getparams ();
Print_r ($arr);

The results of the operation are as follows:
Copy the Code code as follows: Array ([_p] + index [_a] = show [x] = [y] + 23)

I hope this article is helpful to everyone's PHP programming.

http://www.bkjia.com/PHPjc/910584.html www.bkjia.com true http://www.bkjia.com/PHPjc/910584.html techarticle php Get URL parameter method summary, PHP get URL parameter This article describes the PHP get URL parameter method. Share to everyone for your reference. As follows: Get the parameters in the URL in php ...

  • 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.