Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@dhrrgn
Created June 19, 2013 15:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhrrgn/5815253 to your computer and use it in GitHub Desktop.
Save dhrrgn/5815253 to your computer and use it in GitHub Desktop.
Parsing basic Jekyll format in PHP
<?php
// Note, you need symfony/yaml to parse the Front Matter
if ( ! Input::hasFile('file'))
{
// Do some fail here
return;
}
$contents = trim(File::get(Input::file('file')->getRealPath()));
if (substr($contents, 0, 3) !== '---')
{
throw new Exception('Bad Formatting');
}
if ( ! ($pos = strpos($contents, '---', 3)))
{
throw new Exception('Bad Formatting');
}
$frontMatter = trim(substr($contents, 3, $pos - 3));
$contents = trim(substr($contents, $pos + 3));
$yaml = new Symfony\Component\Yaml\Parser\Parser();
$fields = $yaml->parse($frontMatter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment