Created
June 19, 2013 15:32
-
-
Save dhrrgn/5815253 to your computer and use it in GitHub Desktop.
Parsing basic Jekyll format in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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