开发者

PHP interpreting jQuery serialized data

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.


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

 $values = array();
 parse_str($str, $values);


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
)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜