Skip to content

Instantly share code, notes, and snippets.

@gboudreau
Created January 29, 2012 12:46
Show Gist options
  • Save gboudreau/1698659 to your computer and use it in GitHub Desktop.
Save gboudreau/1698659 to your computer and use it in GitHub Desktop.
Testing recursive_include_parser function for Greyhole
<?php
file_put_contents('file1',
"this is file 1\r
include = file2
include = file3 # comment");
file_put_contents('file2', "this is file 2");
file_put_contents('file3',
"this is file 3
include = file4
");
file_put_contents('file4', "this is file 4");
function recursive_include_parser($file) {
$regex = '/^[ \t]*include[ \t]*=[ \t]*([^#\r\n]+)/im';
if (is_array($file) && count($file) > 1) {
$file = $file[1];
}
$file = trim($file);
if (file_exists($file)) {
return preg_replace_callback($regex, 'recursive_include_parser', file_get_contents($file));
} else {
return false;
}
}
$config_text = recursive_include_parser('file1');
var_dump($config_text);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment