-1

Possible Duplicate:
How to explode URL parameter list string into paired [key] => [value] Array?

Quick question

I have a URL sting that I wish to output the Key value as an array eg

$url ="www.domain.com?test=1&test2=2&test3=3";

and wish to have the output as an array

key => value so I can call any of the keys

eg

array (
    test => 1,
    test1 => 2,
    test2 => 3,
)

cant use explode & Just thinking do i have to do a loop and match between & and = for the key

Community
  • 1
  • 1
user1217917
  • 643
  • 1
  • 6
  • 8

1 Answers1

2

I would use parse_url() with parse_str():

$url = parse_url('www.domain.com?test=1&test2=2&test3=3');
parse_str($url['query'], $keyvalue);

var_dump($keyvalue);

$keyvalue should contain your desired array.

Benjamin Paap
  • 2,744
  • 2
  • 21
  • 33