I need to write a basic script / template engine that will work under PHP. Ideally, I could mix my own markup language with an (X) HTML template and run the document through a server-side parser to dynamically replace my own markup with HTML code from the database.
Unfortunately, despite all my knowledge of PHP and scripts, I'm not quite sure where to start. My first instinct was to run the entire document through some sort of regular expression parser and display my own markup for certain PHP functions ... but this seems a bit slow and hard for me.
What resources / tutorials / examples exist that can point me in the right direction? For comparison, I really like the new template engine for Razor for .NET MVC ... I don't want to completely disable it for a PHP project, but creating something like that would be great.
Update
OK, let me clarify my explanation a bit more ... I am developing websites for WordPress. Many of my clients want to set up their websites, but run away when I start talking about PHP. It is a scripting language that looks too complicated for a simple user, even to be interested.
I want to create my own markup form specifically for WordPress. So instead of having calls to PHP functions ( get_header() and get_footer() and if(has_posts()) ...) in the theme file, you would have to have an XML namespace ( <wpml:header /> and <wpml:footer /> and <wpml:loop> ... </wpml:loop> ), which translates to the same thing. It would be better to separate the template files from the server-side script (there are several themes that place entire PHP functions directly in the PHP template files!), And itโs easier for non-developers to get started with setting up a WordPress theme.
With this in mind, the already proposed solutions TWIG and Mackrell definitely support the idea of โโembedding script "nuggets" in a file, but they really do not help me parse custom XML / XHTML markup into something recognizable by server code.
So ... where to start when I create a new server-side markup processor?
scripting xml php markup templates
Eamann
source share