PHP unserialize viewer

This PHP unserialize viewer decodes a serialize() string into a data tree and JSON, finds the error position in a broken string, and fixes wrong string lengths.
Input
For example, a value from the WordPress wp_options table, up to 262,144 bytes.

Decoding runs in the browser and requires JavaScript.

Everything runs in your browser; nothing is sent or stored.

  • Paste a value from the database, for example from the wp_options table, into the "PHP serialize() string" field. The field includes a sample string.
  • As you type, the data is shown in the "Data structure" section, with the type and length of each value, and in the "JSON" section. The tool only displays the data, and it does not create objects or run code.
  • For a broken string, a message shows the position of the error, and clicking "Show" moves the cursor to that position in the field.
  • When a string length is wrong, click "Fix lengths" and copy the string from the "String with fixed lengths" section.
  • To copy the data as JSON, click "Copy" under the "Data in JSON format" field.

What the PHP serialize() format is

The PHP serialize() function turns arrays, objects, and simple values into a single text string that can be stored in a database or a file, and the unserialize() function restores the original data from that string. Each value in the string starts with a letter that indicates its type, for example s for a string, i for an integer, and a for an array. WordPress stores theme, widget, and plugin settings in serialize() format, in tables such as wp_options and wp_postmeta.

Why a database search and replace breaks the string

Each string in the format is preceded by its length in bytes, for example s:4:"Erez";. Replacing text directly in the database, such as the site address after a move to a new domain, changes the string but does not update the length before it, so the unserialize() function fails. WordPress then cannot read the value, and widgets and theme settings may disappear from the site. That is why a search and replace in serialized data is done with tools that also update the lengths, such as the WP-CLI wp search-replace command.

Security: unserialize() and untrusted input

Running unserialize() in PHP code on user input is unsafe, because the string can create objects of any class that exists in the application and trigger their magic methods, such as __wakeup() and __destruct(). This type of vulnerability is called PHP Object Injection. To pass data between systems, or from the browser to the server, JSON is the better format, with the json_encode() and json_decode() functions. When you do need unserialize(), you can limit the classes that it is allowed to create with the allowed_classes option.

Values in serialize() format

  • N;the null value.
  • b:1;the boolean value true.
  • i:42;the integer 42.
  • d:0.1;the floating-point number 0.1.
  • s:5:"café";the string "café", 5 bytes long.
  • a:2:{i:0;s:3:"one";i:1;s:3:"two";}an array with two elements and the keys 0 and 1, shown in JSON as an array.
  • a:1:{s:4:"name";s:4:"Erez";}an array with a string key, shown in JSON as an object.
  • O:8:"stdClass":1:{s:4:"name";s:4:"Erez";}an object of the stdClass class with one property. In JSON, the class name is shown in the __class field.
  • E:11:"Status:Open";the Open case of the Status enum, shown as Status::Open.

PHP unserialize viewer FAQ

Why is the length of a string with accented letters greater than its number of letters?

The length before each string is measured in bytes, not characters. In UTF-8 encoding, an accented letter such as é takes 2 bytes, as does each letter in alphabets such as Hebrew, Greek, or Cyrillic, so the word "café", which has 4 letters, has a length of 5 bytes. An unaccented Latin letter, a digit, or a space takes 1 byte.

What does the message about extra characters after the end of the data mean?

The message appears when the string is valid but is followed by extra characters, for example a line that was copied by mistake. The data is shown up to the end of the valid string, and the message gives the position of the first extra character.

Does fixing the lengths work for every broken string?

The fix only handles string lengths that do not match the content, which is the common problem after a search and replace in the database. When the string was cut off or has a different error, the "Fix lengths" button is not available, and you can restore the value from a backup. When the correct length of a string cannot be determined, the message says so.

How are protected and private properties shown?

In the "Data structure" section, a protected property is shown with the :protected suffix, and a private property is shown with the class name and the :private suffix, as in the output of the var_dump() function. In the JSON, the properties are shown with the same suffixes.

Which data types does the viewer support?

The viewer supports null values, booleans, numbers, strings, arrays, objects, enums, and references (r and R). An object in a custom format (C) is shown as is, without decoding its inner content, and the S type is not supported.

Is there a limit on the size of the string?

The field accepts a string of up to 262,144 bytes (256 KiB), with up to 64 levels of nesting. The "Data structure" section shows only the first 2,000 values, and a string longer than 300 characters is shown shortened, but the JSON always includes all the data.

Shopping cart

Your cart is emptyYou can start with one of our popular plans.

Site search

Accessibility

Text size
100%
Accessibility statement