tags:

views:

67

answers:

2

I have a form that is capturing data sent from a google LocalSearch API. The user has the ability to select a specific result, some or all results via a checkbox i'm injecting into the form with jQuery. The checkbox value looks something like this:

title=Emijean+Web+Design+and+Management&streetAddress=63+James+St.&city=Parry+Sound&region=ON

So if I had multiple checkboxes they would all contain similar data and the post value for checkboxes addToDb[] would be an array full of the above.

What's the best way for me capture this data with my php script? I can figure it out using foreach, explode, etc. but I'm sure there must be a way to unserialize a javascript string using PHP that's more efficient.

Any ideas on how I could get output similar to this:

array(
  [0] => array(
    title => "Emijean Web Design and Management"
    streetAddress => "63 James St."
    city => "Parry Sound"
    region => "ON"
  )
)

Thanks everybody.

+1  A: 

What you need is *parse_str*:

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

parse_str("title=Emijean+Web+Design+and+Management&streetAddress=63+James+St.&city=Parry+Sound&region=ON");
print_r(get_defined_vars());

outputs

Array
(
    [title] => Emijean Web Design and Management
    [streetAddress] => 63 James St.
    [city] => Parry Sound
    [region] => ON
)
knoopx
+2  A: 

That's a querystring format - you can use parse_str():

 $values = array();
 parse_str($str, $values);
Greg
Thanks knoopx, you're right too. I enjoyed having an example from Greg. This is perfect.
jeerose