How do I PHP-unserialize a jQuery-serialized form?

Gene Bean picture Gene Bean · Nov 24, 2009 · Viewed 209.1k times · Source

Using $('#form').serialize(), I was able to send this over to a PHP page. Now how do I unserialize it in PHP? It was serialized in jQuery.

Answer

Chris Allen Lane picture Chris Allen Lane · Sep 28, 2010

Provided that your server is receiving a string that looks something like this (which it should if you're using jQuery serialize()):

"param1=someVal&param2=someOtherVal"

...something like this is probably all you need:

$params = array();
parse_str($_GET, $params);

$params should then be an array modeled how you would expect. Note this works also with HTML arrays.

See the following for more information: http://www.php.net/manual/en/function.parse-str.php

Hope that's helpful. Good luck!