W3docs

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

In PHP, you can use the unserialize function to unserialize a serialized string.

In PHP, you can use the parse_str function to parse a jQuery-serialized form string into an array. jQuery's serialize() method outputs data as a URL-encoded query string, which parse_str handles natively.

Example of using parse_str() to parse a jQuery-serialized form in PHP

<?php

$formData = 'username=John&email=john%40example.com&agree=on';
parse_str($formData, $formArray);

print_r($formArray);

This will create an associative array containing the data from the serialized form. You can then access the individual form elements by key in the array.

For example, if the form contained an input field with the name "username", you could access the value of that field like this:

Example of accessing the value of an input field in PHP

echo $formArray['username']; // Outputs: John

Note: parse_str is specifically designed for URL-encoded query strings. If you ever need to work with data serialized by PHP's serialize() function, you would use unserialize() instead, but these two formats are completely different.