0

I'm passing through a string via ajax to be used with PHP.

Example

home?area=Ohio&country=United%20States

How can I end up with an array that looks like the following?

array('area' => 'ohio', 'country' => 'United States');
PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Nick Shears
  • 1,103
  • 1
  • 13
  • 30
  • What is the difference between the wanted array and `$_GET`? – kero Nov 27 '13 at 00:11
  • `parse_str`, possibly in tandem with `parse_url` if you have an entire url and you need to seperate the query string out of it. – Wrikken Nov 27 '13 at 00:12
  • There isn't, the data is being sent to a different file via POST, so the GET variables aren't accessible. – Nick Shears Nov 27 '13 at 00:12

2 Answers2

1

Assuming you're using the current request's query string, try:

parse_str($_SERVER['QUERY_STRING'], $output);

echo $output['area']; // Ohio
Ryan Nigro
  • 4,389
  • 2
  • 17
  • 23
1
parse_str("area=Ohio&country=United%20States");

http://us2.php.net/manual/en/function.parse-str.php

Antony Harder
  • 423
  • 4
  • 9