Using php functions pase_url() and parse_str() we can retrieved the parameter value from a URL string.
As URL parameters are always separated by the ? character. so using parse_url() php function, we can retrieve all parameters value by parse an URL and this function will return an associative array which contains its various components.
Syntax:
$parseurl = parse_url($url)
In same way parse_str() function is used to parse a query string into variables. The string passed to parse_str() function for parsing is in the format of a query string passed via a URL.
Syntax:
parse_str($parseurl['query'], $data);
Below examples uses parse_url() and parse_str() function to get the parameters value from URL string.
<?php
$url = 'https://www.yourdomain.com/?country=UK&state=London&city=London';
$parse_ary = parse_url($url);
// check parameters exiting in url or not
$return_val = '';
if(isset($parse_ary['query'])) {
parse_str($parse_ary['query'], $data); // parse the associated array
echo $parse_ary['country']; // country
echo $parse_ary['state'];// state
echo $parse_ary['city']; // city
}