Hailwood Posted April 14, 2010 Share Posted April 14, 2010 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 More sharing options...
AdRock Posted April 14, 2010 Share Posted April 14, 2010 the 41 should have a variable assigned to it like ?page=41 or whatever name you want the you would use $_GET['page']; Link to comment https://forums.phpfreaks.com/topic/198462-_get-key-value/#findComment-1041394 Share on other sites More sharing options...
Hailwood Posted April 14, 2010 Author Share Posted April 14, 2010 yeah, I have no control over how they pass it to me, and this is the method they have chosen to use. With no actual named variable Thanks though. Any more ideas? Link to comment https://forums.phpfreaks.com/topic/198462-_get-key-value/#findComment-1041396 Share on other sites More sharing options...
Domcsore Posted April 14, 2010 Share Posted April 14, 2010 Could you post a link to the method you have used because this sounds unusual? Link to comment https://forums.phpfreaks.com/topic/198462-_get-key-value/#findComment-1041399 Share on other sites More sharing options...
Hailwood Posted April 14, 2010 Author Share Posted April 14, 2010 Could you post a link to the method you have used because this sounds unusual? Method I have used for what exactly? The 41 is coming from another site (not controlled by me) My job is to simply fetch it. Link to comment https://forums.phpfreaks.com/topic/198462-_get-key-value/#findComment-1041400 Share on other sites More sharing options...
ChemicalBliss Posted April 14, 2010 Share Posted April 14, 2010 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 . -cb- Link to comment https://forums.phpfreaks.com/topic/198462-_get-key-value/#findComment-1041408 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.