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? Quote Link to comment 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']; Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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- Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.