Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - How to get $_GET Parameter without value

Tags:

php

parse-url

I need to know how to get the $_GET parameter from requested url. If I use for example

$url = $_SERVER['REQUEST_URI'];
$parse_url = parse_url($url, PHP_URL_QUERY);

echo $parse_url; will output query=1, but I need only the parameter not parameter AND value to check if parameter is in array.

like image 324
Serpentdriver Avatar asked Feb 14 '26 16:02

Serpentdriver


1 Answers

Based on your example, simply exploding the = might quickly suits your need.

$url = $_SERVER['REQUEST_URI'];
$parse_url = parse_url($url, PHP_URL_QUERY);
$queryparam = explode("=", $parse_url);
echo $queryparam[0];
/* OUTPUT query */

if (in_array($queryparam[0], $array_of_params)){ ... }

But you can simply achieve the same thing like this:

if (@$_GET["query"] != ""){ ... }
like image 99
NVRM Avatar answered Feb 16 '26 10:02

NVRM