PHP: GET THE FULL QUERY STRING

Tutorials Algorithms Analysis of Algorithms Data Structures Languages Interview Corner GATE ISRO CS UGC NET CS CS Subjects Web Technologies Student Jobs
*

*

*

*

The parameters from a URL string can be be retrieved in PHPhường using pase_url() & parse_str() functions.

Bạn đang xem: Php: get the full query string

Note: Page URL và the parameters are separated by the ? character.

parse_url() Function: The parse_url() function is used khổng lồ return the components of a URL by parsing it. It parse an URL và return an associative sầu array which contains its various components.

Xem thêm: How To Install Php On Windows : Home, Binaries And Sources Releases

Syntax:

parse_url( $url, $component = -1 )parse_str() Function: The parse_str() function is used to parse a query string into lớn variables. The string passed lớn this function for parsing is in the format of a query string passed via a URL.


Syntax:

parse_str( $string, $array )Approach: Parse the URL string using parse_url() function which will return an associative sầu array that contains its (passed URL) various components. The query of the array returned by parse_url() function which contains a query string of URL.

Below examples uses parse_url() và parse_str() function to lớn get the parameters from URL string.Example 1:


// Inintialize URL khổng lồ the variable
$url = "http://www.obatambeienwasirherbal.com?name=Tonny";
// Use parse_url() function to lớn parse the URL
// and return an associative sầu array which
// contains its various components
$url_components = parse_url($url);
// Use parse_str() function lớn parse the
// string passed via URL
parse_str($url_components<"query">, $params);
// Display result
eđến " Hi ".$params<"name">;
?>
Output:

Hi Tonny
Example 2:


// Inintialize URL khổng lồ the variable
$url = "http://www.obatambeienwasirherbal.com/register?name=Amit&email=amit1998
email.com";
// Use parse_url() function lớn parse the URL
// và return an associative array which
// contains its various components
$url_components = parse_url($url);
// Use parse_str() function khổng lồ parse the
// string passed via URL
parse_str($url_components<"query">, $params);
// Display result
echo " Hi ".$params<"name">." your emailID is ".$params<"email">;
?>
Output:

Hi Amit your emailID is amit1998
tin nhắn.com
My Personal Notes arrow_drop_up
Save
favorite_border Like
Next last_page
Get the full URL in PHPhường
Recommended Articles
Page :
JavaScript | Know the value of GET parameters from URL
14, Atruyền thông quảng cáo 19
How khổng lồ get URL Parameters using JavaScript ?
13, Dec 19
How to lớn serialize an object into lớn a các mục of URL query parameters using JavaScript ?
28, Jun 19
How to lớn get danh sách of parameters name from a function in Python?
22, Dec 20
How khổng lồ retrieve GET parameters from JavaScript ?
31, Dec 20
Convert relative sầu path URL khổng lồ absolute path URL using JavaScript
30, Jan 20
Get the full URL in PHP
25, Sep 18
Program lớn get the subdomain name of a URL using PHP
11, Feb 19
JavaScript method lớn get the URL without query string
30, May 19
How to check if URL contain certain string using PHP?
08, Feb 19
Firebase to get url
01, Mar 19
Get the current URL using jQuery?
13, May 19
How lớn get protocol, tên miền and port from URL using JavaScript ?
30, May 19
Get the YouTube video ID from a URL using JavaScript
31, May 19
How lớn get the fragment identifier from a URL ?
19, Dec 19
How khổng lồ get the tệp tin name from page URL using JavaScript ?
29, Jan 20
How to lớn get the new image URL after refreshing the image using JavaScript ?
29, Jun 20
How to lớn get the current URL using JavaScript ?
13, Jul 20
How lớn get the current URL using AngularJS ?
28, Sep 20
JavaScript | Passing parameters to a callbaông chồng function
31, May 19
JavaScript | Function Parameters
07, Mar 19
Perl | Passing Complex Parameters khổng lồ a Subroutine
07, May 19
How khổng lồ declare the optional function parameters in JavaScript ?
10, Jun 19
How to Create Query Parameters in JavaScript ?
18, Mar 20
Article Contributed By :

*

Blinkii
Blinkii
Vote for difficulty
Easy Normal Medium Hard Expert
Report Issue
What’s New
Data Structures và Algorithms – Self Paced Course
View Details
Ad-Free Experience – obatambeienwasirherbal.com Premium
View Details
Most popular in PHP
Most visited in PHPhường. Programs

Writing code in comment? Please use ide.obatambeienwasirherbal.com, generate link & chia sẻ the link here.


Load Comments
5th Floor, A-118, Sector-136, Noida, Uttar Pradesh - 201305
feedback
obatambeienwasirherbal.com
Company Learn Practice Contribute
obatambeienwasirherbal.com , Some rights reserved
We use cookies lớn ensure you have sầu the best browsing experience on our trang web. By using our site, you acknowledge that you have sầu read và understood our Cookie Policy và Privacy Policy Got It !