Home › Developer Tools › PHP Unserialize Online

PHP Unserialize Online

Paste a string produced by PHP's serialize(), such as a WordPress option, a session or a cache value, and read it as JSON, a collapsible tree, print_r() or var_export() output. Broken string lengths after a database search-and-replace are repaired automatically, and a second tab turns JSON back into PHP serialized format.

Last updated:

Result

Decoding happens in your browser with a safe parser: no PHP code runs, no objects are instantiated, and nothing is uploaded.

Advertisement
Advertisement

How to use the PHP Unserialize Online

  1. Paste the serialized string into the left box or open a text file. A sample WordPress-style option is loaded to start with.
  2. Pick a view: JSON, Tree, print_r() or var_export(). With Live update on, the result refreshes as you type.
  3. Fix broken data: keep Repair wrong string lengths on, then press Copy repaired string to get a valid value to save back.
  4. Copy or download the decoded result.
  5. Going the other way? Open the Serialize tab, paste JSON and copy the PHP serialized string.

PHP serialize() format reference

Every value starts with a one-letter type marker. Lengths and counts are written before the data, and string lengths are measured in bytes.

MarkerPHP typeExampleMeaning
NnullN;NULL value
bboolb:1;true (1) or false (0)
iinti:-42;Integer
dfloatd:0.1; d:INF;Floating point, also INF, -INF and NAN
sstrings:5:"Café";Byte length, then the raw bytes in quotes
aarraya:2:{i:0;s:1:"x";s:1:"k";b:1;}Element count, then key/value pairs
OobjectO:8:"stdClass":1:{s:2:"id";i:7;}Class name length, class name, property count, properties
CSerializable objectC:3:"Foo":4:{data}Custom payload from a class implementing Serializable
Eenum (PHP 8.1+)E:11:"Suit:Hearts";Enum class and case name
r / RreferenceR:2;Points back to the n-th value written (1-based)

Private properties are stored as \0ClassName\0prop and protected ones as \0*\0prop, where \0 is a NUL byte. That is why the declared length of a private property name is longer than the visible name, and why copying such data through some editors that drop NUL bytes breaks it.

Fixing broken serialized data

  • Search-and-replace damage: replacing http://old.test with https://www.new-site.com directly in SQL changes the string but not its s:N: prefix, so PHP's unserialize() returns false. Paste the value here, keep the repair option on and copy the repaired string. For whole databases, use a serialization-aware search-and-replace tool instead of plain SQL.
  • Encoding changes: converting a table from Latin-1 to UTF-8 changes byte counts of accented letters; the repair recalculates them in UTF-8.
  • Escaped quotes: data copied from PHP source or a SQL dump may contain \" instead of ". Unescape it first (for example with find and replace) before decoding.
  • Prefer JSON for new code: json_encode() is portable, readable in any language and safe to decode. Keep serialize() for data that already uses it.

Frequently asked questions

What does PHP unserialize do?

unserialize() turns the text produced by serialize() back into a PHP value. The format stores the type and size of every value, for example s:5:"hello"; is a 5-byte string and a:2:{...} is an array with two elements. This tool reads the same format and shows it as JSON or a tree without running PHP.

Why does my serialized string fail with an offset error in PHP?

Usually because a string's declared byte length no longer matches its content. This happens after a plain search-and-replace in a database (for example changing a domain name in WordPress) or when a multibyte character was counted as one byte. Keep Repair wrong string lengths on and copy the repaired string.

Are string lengths counted in characters or bytes?

In bytes of the stored encoding, normally UTF-8. "Café" is s:5 because é takes two bytes, and most emoji take four. The tool counts UTF-8 bytes in both directions.

Is it safe to unserialize untrusted data?

In PHP, calling unserialize() on user input is risky because it can create objects and trigger magic methods such as __wakeup or __destruct (object injection). This tool never runs PHP or creates objects, so inspecting data here is safe. In your own code prefer json_decode, or pass ['allowed_classes' => false] to unserialize.

How are PHP objects shown in JSON?

Object properties become JSON keys, and with Keep class names on a "__class" key holds the class name. Private and protected property names, which PHP stores with hidden NUL-byte prefixes, are cleaned up; the Tree and print_r views show their visibility.

Why did a float become an integer when serializing JSON?

JSON has a single number type, so 1.0 and 1 are identical after parsing. Whole numbers become PHP integers (i:), while numbers with a fractional part or exponent become floats (d:).

What are r: and R: in serialized data?

They are back-references to a value that appeared earlier, counted from 1 in the order values were written. R: is a PHP reference (&$var) and r: is a repeated object handle. The tool resolves them and marks circular ones as *RECURSION*.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

JSON to PHP ArrayConvert JSON to PHP array code (short [] or array()) and PHP arrays back to JSON.PHP FormatterBeautify PHP code with Prettier PHP: PSR-12 style, indent and brace options, syntax errors.JSON FormatterBeautify, minify and validate JSON, with a collapsible tree view.PHP Online CompilerRun PHP 8 code in your browser with output, HTML preview, error lines and share links.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.JSON SorterSort JSON keys A-Z recursively, sort arrays by value or by a key, then pretty-print or minify.JSON to HTML TableConvert a JSON array of objects into clean HTML table code with CSS styles and a live preview.CSV to SQL ConverterConvert CSV to SQL CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server.IPv4 to IPv6 ConverterConvert IPv4 to IPv4-mapped, 6to4 and NAT64 IPv6, extract IPv4 from IPv6, and get int/hex/binary.cURL to Code ConverterConvert curl commands to JavaScript fetch, Axios, Python requests, Node.js, PHP and Go code.Code to ImageTurn code into a beautiful syntax-highlighted PNG with themes, window frame and background.Excel to JSON ConverterConvert Excel sheets (XLSX, XLS, ODS) to JSON with header row, type and shape options.CSV to Excel ConverterConvert CSV files to a real .xlsx workbook with typed numbers and dates, one sheet per file.CSV SplitterSplit a large CSV into smaller files by row count, file count or column value, header kept.CSV MergerCombine many CSV files into one, matching columns by name, with dedupe and a source column.VCF to CSV ConverterConvert vCard (.vcf) contacts to CSV for Google or Outlook, or turn a CSV back into a VCF.Calendar Event (.ics) GeneratorCreate an .ics calendar invite with time zone, reminders and repeats + Google/Outlook links.CSV Column ExtractorPick, reorder and rename CSV columns, filter rows by value, and export a new CSV or JSON.CSV Diff CheckerCompare two CSV files by key column and see added, removed and changed rows cell by cell.CSV Duplicate Row RemoverRemove duplicate rows from a CSV by all or selected columns and download the cleaned file.CSV to HTML TableTurn CSV into clean HTML table code with a live preview, styling options and one-click copy.CSV to Markdown TableConvert CSV to a neatly aligned GitHub Markdown table with column alignment and live preview.CSV TransposeSwap rows and columns of CSV, TSV or pasted spreadsheet data, with delimiter auto-detect.Date Format ConverterConvert any date to ISO 8601, RFC 2822, Unix time and custom strftime, moment or Java patterns.ENV to JSON ConverterConvert .env files to JSON or YAML and JSON back to .env, with quotes and multiline values.File to Base64Convert any file to a Base64 string or data URI with MIME detection, line wrap and download.HTML Table to CSVExtract any table from HTML or page source to CSV, TSV or JSON, with colspan and rowspan handled.IEEE 754 Floating Point ConverterConvert decimals to 32/64-bit IEEE 754 floats: toggle bits, see hex, exact value and rounding error.INI to JSON ConverterConvert INI and CFG files to JSON and JSON back to INI, with sections, arrays and types.IP Address ConverterConvert IPv4 to decimal, hex, binary, octal and back, with class and private/public check.ISBN Converter & ValidatorConvert ISBN-10 to ISBN-13 and back, validate check digits and hyphenate, one or in bulk.JSON Flatten / UnflattenFlatten nested JSON to dot or bracket path keys, or unflatten flat keys back to nested JSON.JSON to Dart ClassTurn JSON into Dart model classes with fromJson, toJson, null safety and nested classes.JSON to Java ClassTurn JSON into Java POJOs or records with Lombok, getters/setters and Jackson or Gson annotations.JSON to Kotlin Data ClassTurn JSON into Kotlin data classes for kotlinx.serialization, Gson, Moshi or Jackson.
See all 129 Data & File Format Converters →