Change language

How do I get parameters from a URL string in PHP?

Note:Page URL and parameters are separated by ?character. The parse_url() function :The parse_url() function is used to return URL components by parsing it. It parses the URL and returns an associative array that contains its various components.Syntax:
parse_url ($url, $component = -1)
The parse_str() function :The parse_str() function is used to parse the query string in variables. The string passed to this function for parse is in the format of a query string passed through a URL.Syntax:
parse_str ($string, $array)
Approach:parse the URL string with the parse_url() function, which will return an associative array containing its (passed URLs) various components. An array query, returned by the parse_url() function, that contains the URL query string.The following examples use the parse_url() and parse_str() functions to get parameters from a URL string. 
Example 1:  
// Initialize the URL for the variable $url = http://www.engineerforengineer.org?name=Tonny ;  
// Use the parse_url() function to parse the URL
// and return an associative array that
// contains various components $url_components = parse_url ( $url );  
// Use the parse_str() function to parse
// string passed through the URL parse_str ( $url_components [ ’query’ ], $params );  
// Show result echo ’Hi’ . $params [ ’name’ ];  
?>
Exit:
Hi Tonny 
Example 2:  
// Initialize the URL for the variable $url = http://www.engineerforengineer.org/register?name=Amit&[email protected] ;  
// Use the parse_url() function to parse the URL
// and return an associative array that
// contains various components $url_components = parse_url ( $url );  
// Use the parse_str() function to parse
// string passed through the URL parse_str ( $url_components [ ’query’ ], $params );  
// Show result echo ’Hi’ . $params [ ’name’ ]. ’your emailID is’ . $params [ ’email’ ];  
?>
Exit:
Hi Amit your emailID is [email protected]

Shop

Best laptop for Sims 4

$

Best laptop for Zoom

$499

Best laptop for Minecraft

$590

Best laptop for engineering student

$

Best laptop for development

$

Best laptop for Cricut Maker

$

Best laptop for hacking

$890

Best laptop for Machine Learning

$950

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

12 answers

NUMPYNUMPY

How to convert Nonetype to int or string?

12 answers

NUMPYNUMPY

How to specify multiple return types using type-hints

12 answers

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

12 answers

Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method