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');
3
  • What is the difference between the wanted array and $_GET? Commented Nov 27, 2013 at 0: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. Commented Nov 27, 2013 at 0:12
  • There isn't, the data is being sent to a different file via POST, so the GET variables aren't accessible. Commented Nov 27, 2013 at 0:12

2 Answers 2

1

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

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

echo $output['area']; // Ohio
Sign up to request clarification or add additional context in comments.

1 Comment

oh wicked, knew there had to be some function for it! cheers.
1
parse_str("area=Ohio&country=United%20States");

https://www.php.net/manual/en/function.parse-str.php

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.