How can I change
{for ...cond.... }
somethinginbetween
{/for}
to
<?php for (...cond...){ ?>
somethinginbetween
<?php } ?>
This is a quick-and-dirty string literal string replacement:
$code = str_replace('{for ', '<?php for (', $code);
$code = str_replace(' }', '){ ?>', $code);
$code = str_replace('{/for}', '<?php } ?>', $code);
It will not work if somethhingbetween contains if(){ } because } gets replaced by ){ ?>. But for other cases with just {for condition } and {/for}, it suffice.
Regular expression approach combined with simple string replacement, this assumes no occurences of } in the for loop (match everything except for }: [^}]+)
$code = preg_replace('/{for ([^}]+)}/', '<?php for ($1) { ?>', $code);
$code = str_replace('{/for}', '<?php } ?>', $code);
This function does no validating whatsoever, it's your responsibility to feed it with properly opened / closed {for} and {/for}s.
If you need to execute PHP, insert PHP. The other way would be writing your own parsing code. You could look at template projects like Smarty.
for != foreach. So you'll have to use something like {for $i=0; $i<2; $i++}...some code...{/for}.{for with <?php for( then replace all {/for} with <?php endfor;?> and in the end any remaining } with ):?>
fortags, or could it any tag using that languagefor(){....}you write:for(): .... endfor;with that you can replace each {for cond} with <?php for(cond):?> and each /for with <?php endfor: ?> the same is applicable to if, foreach, switch ..... see here php.net/manual/de/control-structures.alternative-syntax.php