formaterTools Logo Formater Tools

PHP Serialize

Convert PHP arrays/objects to serialized strings. Paste your PHP array/object below.

What PHP's Serialize Format Actually Looks Like

PHP's serialize() function turns a value into a length-prefixed string representation rather than JSON. A string is written as s:5:"hello";, an integer as i:42;, and an array as a:2:{i:0;s:3:"foo";i:1;s:3:"bar";} — the a:2 means two key/value pairs follow. This tool runs that exact format conversion in your browser so you can see the byte-accurate output PHP would produce with serialize().

Where You'll Actually Run Into This Format

WordPress wp_options / postmeta

WordPress stores arrays (plugin settings, widget config) as serialized strings in the database. Editing one by hand in phpMyAdmin means recomputing the length manually — this tool does that for you.

Session & cache storage

The default PHP session handler and file-based caches often serialize objects before writing them to disk, since the format preserves type information that JSON drops (e.g. int vs numeric string).

Legacy API payloads

Some older PHP APIs and CMS exports still ship serialized strings instead of JSON. Converting a sample payload here lets you see the underlying structure without spinning up PHP.

Debugging without a PHP shell

If you're reviewing a database dump or log on a machine without PHP installed, this tool lets you serialize a test value to compare against what you're seeing in the data.

The Classic Gotcha: Length Corruption

Because every string is prefixed with its byte length (s:5:"hello"), editing a serialized value directly in a text editor or find-and-replace tool almost always breaks it — changing "hello" to "hi" leaves the length at 5 while the string is now 2 bytes, and PHP's unserialize() will fail or truncate. If you need to search-and-replace inside serialized data (a common WordPress migration task), you have to regenerate it through serialize/unserialize rather than editing the text directly — this is exactly the round trip this tool and its Unserialize counterpart are for.

Frequently Asked Questions

Why not just use JSON instead?

JSON is more portable across languages, but PHP's serialize format preserves PHP-specific type distinctions (integer vs. string, associative vs. indexed array) and can represent private/protected object properties, which json_encode() cannot do without extra work.

Can this serialize PHP objects, not just arrays?

This tool works on data you paste in a PHP-array-literal style; full object serialization depends on the class definition being available, which only matters when you unserialize it back in real PHP.

Is my data sent to a server?

No. The conversion runs entirely in your browser's JavaScript engine — nothing you paste here is transmitted or logged.

Why did my serialized string fail to unserialize elsewhere?

The most common cause is a length mismatch from manual editing (see above), followed by character-encoding differences (multi-byte UTF-8 characters count as more than one byte in the length prefix).