Communities for your favorite technologies. Explore all Collectives
Ask questions, find answers and collaborate at work with Stack Overflow for Teams.
Ask questions, find answers and collaborate at work with Stack Overflow for Teams. Explore Teams
Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
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');
$_GET
parse_str
parse_url
Assuming you're using the current request's query string, try:
parse_str($_SERVER['QUERY_STRING'], $output); echo $output['area']; // Ohio
Add a comment
parse_str("area=Ohio&country=United%20States");
https://www.php.net/manual/en/function.parse-str.php
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
$_GET?parse_str, possibly in tandem withparse_urlif you have an entire url and you need to seperate the query string out of it.