If it's licensed, and you decide to use portions of the code, yes you have to make it the same license. Now that is not to say that you can't look at how they do it, and develop your own code. The thing here is copying versus learning.
For example: Everything on this board is technically the thoughts and ideas of everyone who posts. If I give you code to use, you copy & paste it and don't give me credit, can I go after you? Probably not. But if I create program / script and you use the same methods to achieve a similar goal (looping in a template) but don't copy my code, can I go after you? Not really. Unless my source-code is closed (think Windows), it's legal to use the same ideas, as long as credit is given.
I'm not a lawyer, so i can't say it's not copyright infringement, but I can say that just because you look at it, doesn't mean you can't develop something very similar. Otherwise, how would we have the Zune, iPod, and Nomad? All serve the same function, all very similar, yet still somewhat different.
Anyway... back to your question. I guess me personally I would do something like this:
<?php
/*
Assuming syntax of something like:
{for start=0 max=10}
<repeatable code />
{/for}
*/
// The HTML output
$htmlOut = '';
preg_match('/{for start=([^\s]*) max=([^\s}]*)}(.*?){\/for}/i', $matches);
if(!empty($matches)) {
// get rid of complete matched text
array_shift($matches);
for($i=0, $k=0, $max=count($matches); $i<$max; $k++) {
$loop[$k]['start'] = $matches[$i++];
$loop[$k]['end'] = $matches[$i++];
$loop[$k]['text'] = $matches[$i++];
}
unset($matches);
foreach($loop as $item)
{
for($i=$item['start']; $i<=$item['end']; $i++)
{
$htmlOut .= parseTplCode($item['text']);
}
}
}
// ... and so on and so on...
?>
That's just example code. Obviously it'd need tweaking and major refinement. But it's just an off the top of my head example.