Skip to content

Instantly share code, notes, and snippets.

@dphiffer
Last active August 29, 2015 14:10
Show Gist options
  • Save dphiffer/63a0e5a5ef8d627b1135 to your computer and use it in GitHub Desktop.
Save dphiffer/63a0e5a5ef8d627b1135 to your computer and use it in GitHub Desktop.
A dumb conversion utility for PHP <=> JSON
<form action="serialize.php" method="post">
<p>JSON:<br>
<textarea name="json" rows="10" cols="80"><?php
if (!empty($_POST['php'])) {
echo json_encode(unserialize($_POST['php']), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}
?></textarea></p>
<p>Serialized PHP:<br>
<textarea name="php" rows="10" cols="80"><?php
if (!empty($_POST['json'])) {
echo serialize(json_decode($_POST['json'], true));
}
?></textarea></p>
<input type="submit">
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment