- preg_match_all: documentation ( source)
<?php
$template = "<html><head><title>{{head}}</title></head><body>{{body}}</body></html>";
preg_match_all("{{(\w*)}}", $template, $matches);
foreach($matches[1] as $var) {
echo $var;
}