Search code examples
phpserializationformattingpretty-printreadability

Can a Serialized PHP Object be formatted for easy readability?


PHP's Serializer produces a byte array which can be displayed as a single-line string via var_dump(). The format of this string is very difficult to read, especially for scenarios such as objects stored in a database.

For the sake of reading these values is it possible to convert these to an indented, formatted readable string? Or is the only option to retrieve them in PHP, unserialize() then, and then do something such as var_dump()?


Solution

  • Here is a great 1 liner:

    <?php echo "<pre>" . print_r(unserialize($yourvar), 1) . "</pre>"; ?>