These scripts convert PHP serialized object format e.g.
a:2:{i:2;a:4:{s:5:"title";s:5:"Hello";s:5:"count";i:0;s:12:"hierarchical";i:0;s:8:"dropdown";i:0;}s:12:"_multiwidget";i:1;}
to YAML format:
---
2:
title: Hello
count: 0
hierarchical: 0
dropdown: 0
_multiwidget: 1
...
YAML was chosen over JSON because JSON loses type information and serializes everything as strings while YAML seems to support at least the datatypes I needed :)
The yaml php lib is not installed by default, see the install-deps-debian.sh
file for installation script for Debian/Ubuntu.
After that you can use the php2yaml
and yaml2php
scripts for conversion.
Example:
echo 'a:2:{i:2;a:4:{s:5:"title";s:5:"Hello";s:5:"count";i:0;s:12:"hierarchical";i:0;s:8:"dropdown";i:0;}s:12:"_multiwidget";i:1;}' > foo.phpobj
./php2yaml < foo.phpobj > foo.yaml
# edit foo.yaml
./yaml2php < foo.yaml > foo.phpobj
cat foo.phpobj
It works even if the php serialization contains embedded linefeeds. No idea about other control characters.
The scripts exit with error code 1 if input cannot be parsed.