Last active
April 5, 2016 02:38
-
-
Save greenbicycle/af77232b738b00bf7adbe225e1fbdad2 to your computer and use it in GitHub Desktop.
Parse yaml section from Markdown file
This file contains 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
#!/usr/bin/env php | |
<?php | |
/* | |
* I like to use Markdown with embedded yaml to store certain info | |
* This is a quick and dirty first attempt. I probably will find some | |
* other chars to add to the preg_match_all pattern. | |
* | |
*/ | |
$file=$argv[1]; | |
if(file_exists($file)) { | |
$input = file_get_contents($file); | |
preg_match_all('|```yaml\n([a-z:\n!\- ./@]*)```|', $input, $matches); | |
var_dump(yaml_parse($matches[1][0])); | |
} else { | |
print "Hang your head in shame. That file does not exist."; | |
} | |
/* | |
This will work on files that are formatted like this: | |
Lorem ipsum, lorem ipmore... | |
```yaml | |
breakfast: yaml for breakfast | |
lunch: yaml for lunch | |
dinner: yaml for dinner | |
``` | |
Morem lorem.... | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment