function parse_template($string) {
$tem =& tem_push();
$tem['pieces'] = array();
- # note: for some reason this captures '<!--' but not '-->'.
- $matches = preg_split("/(<!--)?(~[^~]*~)(?(1)-->)/", $string, -1, PREG_SPLIT_DELIM_CAPTURE);
+ $matches = preg_split('/(<!--)?(~[^~]*~)(?(1)-->)/', preg_replace('/<!--(~[^~]*~)-->/', '$1', $string), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
foreach($matches as $match) {
if($match == '~~') $match = '~';
if(substr($match,0,1) == '~' and strlen($match) > 2) {
} else { # value slot
$tem['pieces'][] = array('name' => $name, 'args' => $args);
}
- } elseif($match and $match != '<!--') { # static string
+ } else { # static string
$tem['pieces'][] = $match;
}
}