I have a HTML form field $_POST[\"url\"]
having some URL strings as the value.
Example values are:
https://example.com/test/1234?email=xyz@test.com
Dynamic function which parse string url and get value of query parameter passed in URL
function getParamFromUrl($url,$paramName){
parse_str(parse_url($url,PHP_URL_QUERY),$op);// fetch query parameters from string and convert to associative array
return array_key_exists($paramName,$op) ? $op[$paramName] : "Not Found"; // check key is exist in this array
}
Call Function to get result
echo getParamFromUrl('https://google.co.in?name=james&surname=bond','surname'); // bond will be o/p here