About PHP Serialize & Unserialize Tool
PHP serialize() turns an array or value into a string such as a:2:{s:4:"name";s:4:"Aman";i:0;i:25;}. WordPress uses it everywhere, for options, post meta and widget settings, so you often meet serialized strings in the database. The numbers after s: are the byte lengths of the strings, which is why serialized data breaks if you change the text by hand.
Choose Encode to turn JSON into a PHP serialized string, with correct UTF-8 byte lengths. Choose Decode to turn a serialized string into readable JSON. The decoder supports null, booleans, integers, floats, strings and arrays, and it refuses serialized objects instead of creating them.
How to use PHP Serialize & Unserialize Tool
- Choose Encode for JSON to serialized, or Decode for serialized to JSON.
- Paste your input and click Run Tool.
- Copy the result. A decode error shows what the parser could not read.
Example
Input
{"name":"Aman","age":25,"tags":["php","wp"],"admin":false}Output
a:4:{s:4:"name";s:4:"Aman";s:3:"age";i:25;s:4:"tags";a:2:{i:0;s:3:"php";i:1;s:2:"wp";}s:5:"admin";b:0;}Common uses
- Reading a serialized option value from the wp_options table.
- Creating a serialized string for a test fixture or a database import.
- Finding out why a search-and-replace on serialized data broke a setting.
Privacy and safety
This tool runs in your browser. The text you enter is processed on your device and is not sent to NHP Learning.
Frequently asked questions
Why does a string length mismatch break serialized data?
The prefix s:5:"Hello" must match the number of bytes. If you replace text in the database without updating the length, PHP cannot unserialize the value. Use WP-CLI search-replace or a plugin that handles serialized data.
Is unserialize() safe on untrusted input?
No. Unserializing data from users can lead to PHP object injection. Use JSON for external data, or pass ['allowed_classes' => false] to unserialize().
Why are objects not supported?
Objects can run code when they are rebuilt. This tool only converts plain data, so it can never trigger a hidden method.