Jump to content

Archived

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

HuggieBear

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

Recommended Posts

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:

[code=php:0]$url = array('firstname' => "richard", 'nickname' => "Huggie");
[/code]

[size=8pt][color=red][b]Edit:[/b][/color][/size] Or even just the field names would be fine.  I'm currently investigating the HTTP extension

Regards
Huggie

Share this post


Link to post
Share on other sites
Use a foreach loop to loop through all variables in the url:
[code=php:0]$url = array();

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


However the following is the same as above:
[code=php:0]$url = $_GET;[/code]


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:
[code=php:0]$url = array();

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

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

Share this post


Link to post
Share on other sites
Something liike the following:
[code]$myarray = array();
foreach($_POST as $key => $val)
  $myarray[$key] = $val;[/code]

Ronald  8)

Share this post


Link to post
Share on other sites
It's so logical, I don't know why I didn't realise that in the first place.

Thanks Wildteen.

Huggie

Share this post


Link to post
Share on other sites
[quote author=wildteen88 link=topic=108274.msg435418#msg435418 date=1158398898]
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:
[code=php:0]$url = array();

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

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

or simply $urlArr = array_keys($_GET);

Share this post


Link to post
Share on other sites

×

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.