I have YAML Front Matter that I want to parse with PHP:
---
title = A nice title goes here
tags = tag1 tag2 tag3
---
This is the content of this entry...
Line2
Line3
I know it's about a Ruby gem of some kind, but I want use this in PHP to create a user-friendly flatfile blog engine.
I also have a snippet from a project called Phrozn. Maybe it can be handy for you guys to see it in order to help me with the problem as best as possible.
private function parse()
{
if (isset($this->template, $this->frontMatter)) {
return $this;
}
$source = $this->readSourceFile();
$parts = preg_split('/[\n]*[-]{3}[\n]/', $source, 2);
if (count($parts) === 2) {
$this->frontMatter = Yaml::load($parts[0]);
$this->template = trim($parts[1]);
} else {
$this->frontMatter = null;
$this->template = trim($source);
}
return $this;
}