I'm doing something similar, but a little different.
Right now I've got a site that uses "xxx.style" as a basis for the page output. "root.style" defines, in relatively simple HTML+customtags, the way all the pages should look.
//It grabs root.style
$rootStyle = readfile("root.style");
/then makes it into one big string, parsing the tags as it goes (readfile makes each line an array element)/
$finalOut="";
for ($i=0; $i<sizeof($rootStyle); $i++) {
$a = $rootStyle[$i];
$a = eregi_replace("%%tag%%", $documentContent, $a);
$finalOut .= $a;
}
/ then it outputs the final product /
echo $finalOut;
}
Keep in mind, this is a very basic version (the one I use has a separate parsing section for multi-line conditional tags. I even got help here with that.)