Skip to content

Instantly share code, notes, and snippets.

@voxpelli
Last active July 14, 2016 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voxpelli/a4fbc66e9bc6dbfec8fa9b7654fdee59 to your computer and use it in GitHub Desktop.
Save voxpelli/a4fbc66e9bc6dbfec8fa9b7654fdee59 to your computer and use it in GitHub Desktop.
{"foo": "bar"}
<div>Hello world</div>
<?php
/**
* Parses JSON front matter into data and content
*
* Example:
*
* {"foo": "bar"}
* <div>Hello world</div>
*/
function get_json_front_matter($data) {
$parts = explode("\n", $data, 2);
return [
'data' => json_decode($parts[0]),
'content' => $parts[1]
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment