Template engine: Include
I'm creating my own template engine using PHP. The basic idea is that for each page (visible for users) there are unique template file with HTML extension. For example...
users-list.php => users-list.html
profile.php => profile.html
about-us.php => about-us.html
I just made comments available in template files (actually HTML). Comments a开发者_如何学编程re visible before processed so real client won't see them, but developer would. Syntax is {* foo *}, and that's made up using regex's. Now I need something like...
{include "header.html"}
I don't know how to write it using code, but, imho, I need something like...
1) Match all {include "xxx"},
2) From matches took string between " and ",
3) Load files content in strings and add to correct place.
something like
preg_replace_callback(
'~{include "(.+?)"}~',
function($m) { return file_get_contents($m[1]) },
$str);
精彩评论