Jump to content


Photo

*SOLVED* Is there a function that can take all the parameters of a URL?


  • Please log in to reply
4 replies to this topic

#1 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 16 September 2006 - 09:05 AM

I want to put all of the parameters of URL into an array, no matter what they are called.  Is there a function for this?

So if my GET url is index.php?firstname=richard&nickname=huggie

I get an array created that would be equivalent to:

$url = array('firstname' => "richard", 'nickname' => "Huggie");

Edit: Or even just the field names would be fine.  I'm currently investigating the HTTP extension

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 16 September 2006 - 09:28 AM

Use a foreach loop to loop through all variables in the url:
$url = array();

foreach($_GET as $key => $value)
{
    $url[$key] = $value;
}


However the following is the same as above:
$url = $_GET;


The $_GET variable is what gets the variables from the url. if you wnat to just get the variable names from thr URL use this:
$url = array();

foreach($_GET as $key => $value)
{
    $url[] = $key;
}

echo "<pre>\n" . print_r($url, true) . '</pre>';


#3 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 16 September 2006 - 09:31 AM

Something liike the following:
$myarray = array();
	foreach($_POST as $key => $val)
	   $myarray[$key] = $val;

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 16 September 2006 - 09:34 AM

It's so logical, I don't know why I didn't realise that in the first place.

Thanks Wildteen.

Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 448191

448191
  • Staff Alumni
  • Advanced Member
  • 3,545 posts
  • LocationNetherlands

Posted 16 September 2006 - 01:26 PM

The $_GET variable is what gets the variables from the url. if you wnat to just get the variable names from thr URL use this:

$url = array();

foreach($_GET as $key => $value)
{
    $url[] = $key;
}

echo "<pre>\n" . print_r($url, true) . '</pre>';


or simply $urlArr = array_keys($_GET);




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users