Use $_GET:
$id = isset($_GET['id']) ? (int) $_GET['id'] : FALSE;
echo '<h1>', $id, '</h1>';
If the URL is inside a variable, use parse_url Docs and parse_str Docs :
$query = parse_url($url, PHP_URL_QUERY);
parse_str($query, $vars);
$id = isset($vars['id']) ? (int) $vars['id'] : FALSE;
echo '<h1>', $id, '</h1>';
Edit:
If you turned on register globals (which is very discouraged, so just for completeness), you can do this:
$id = isset($id) ? (int) $id : FALSE;
echo '<h1>', $id, '</h1>';
Usually in an application you want to de-pair out $_GETand wrap it in a request object:
class Request
{
public function getParameter($name, $default = NULL)
{
return isset($_GET[$name]) ? $_GET[$name] : $default;
}
public function getParameterInt($name, $default = NULL)
{
$value = $this->getParameter($name, NULL);
return NULL === $value ? $default : (int) $value;
}
}
$request = new Request();
$id = $request->getParameterInt('id');
echo '<h1>', $id, '</h1>';
, , , http. .