I use this pattern:
'/({for) (\d+) (times})([\w+\d+{}]{0,})({endfor})/i'
to convert
{for 3 times}App2{endfor}
in
App2 App2 App2
But this do not work with:
{for 7 times}
App2
{endfor}
This is a little piece of my very little template engine.
It's just for fun
$mactos = Array(
'/({for) (\d+) (times})([\w+\d+{}]{0,})({endfor})/i' => '<?php for($i=0;$i<${2};$i++) : ?> ${4} <?php endfor; ?' . '>',
'/({{)(\w+)(}})/i' => '<?php echo $${2}; ?' . '>'
);
$php = file_get_contents('teamplate.php');
foreach ($this->getPatternAndReplacement() as $pattern => $replacement) {
$php = preg_replace($pattern, $replacement, $php);
}
I've read that (...) catch anything but with
'/({for) (\d+) (times})(...)({endfor})/i'
does not work =(.