To get parameters from a URL string in PHP, the code is as follows−
Example
<?php $url = 'https://www.example.com/register?name=demo&[email protected]'; $res = parse_url($url); parse_str($res['query'], $params); echo 'Email = '.$params['email']; ?>
Output
This will produce the following output−
Email = [email protected]
Example
Let us now see another example −
<?php $url = 'https://www.example.com/register?name=demo&[email protected]'; $res = parse_url($url); parse_str($res['query'], $params); echo 'Email = '.$params['name']; ?>
Output
This will produce the following output−
Email = demo