Jump to content

$_GET key == value?


Hailwood

Recommended Posts

Hi guys,

 

 

If i have a url such as

www.example.com?41

how do i get the 41?

 

 

I ak as this is what i am passed from another site, so i do not know the actual value.

 

 

I came up with:

 

 


foreach($_GET as $k => $v)
    $id = $k;
echo $id;

 

 

but it is rather inefficient.

 

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/198462-_get-key-value/
Share on other sites

well if your going for efficiency:

 

If this is the definite format, with a single argument, no assignment, then this is your code:

$_SERVER['QUERY_STRING'];

 

-cb-

 

On a side note, if you know its to be a number, but the length of digits and number of arguments may vary then something like this should be pretty efficient:

preg_match("/^[0-9]+/",$_SERVER['QUERY_STRING'],$match);
$number = $match[0];

Of Course, only if you know it will be the first argument :P.

 

-cb-

Link to comment
https://forums.phpfreaks.com/topic/198462-_get-key-value/#findComment-1041408
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.