A: 

Every template language has its own way of approaching the problem. You could, instead of writing your own template language from scratch, use one of the standard ones out there like Smarty.

If you are writing your own, you'll need at a minimum a construct that will let you express loops and conditionals. One simple approach that I've seen used before is something like:

<!-- BEGIN conditional_or_looped_block_named_foo -->
Stuff that may appear zero or more times
<!-- END conditional_or_looped_block_named_foo -->

The syntax varies widely, of course, from one language to another, but the basic approach is the same: have some markup that surrounds the portion of code you want to isolate and repeat (or omit).

VoteyDisciple
Okay, so i would need to create my own construct in my templates and then parse and replace them with regular php functions, and then continue like I had before. I've heard from a lot of people not to use smarty, for one reason or the other, so id rather just create my own.
BDuelz
A: 

This should give you an idea: http://www.handyphp.com/index.php/PHP-Resources/Handy-PHP-Tutorials/Creating-Your-First-Template-Driven-PHP-Website-Part-2.html

I found it by doing a quick search, it has code to do what you are asking, it does search and replace with simply variables that you have created.

So your foreach() call would not echo but store in a variable, then you replace that variable with {users} in the template.

Jakub
+1  A: 

For these "{tags}" type template you have a very popular engine: Smarty

inakiabt
A: 

Smarty is too redundant! Your class with the function of cutting a page is enough.

blankyao