A simple php template parser.
template-parser replaces all placeholders in html template with actual values.
Simply instantiate TemplateParser with a link to the HTML template.
Let's say that we have an html template called profile.tpl :
<h1>{username} profile</h1>
<p><b>Name:</b> {name}</p>
<p><b>Email:</b> {email}</p>
<p><b>Location:</b> {location}</p>You can parse it like this:
include("TemplateParser.php");
// Load the template file
$profile = new TemplateParser("profile.tpl");
$data = array("username" => "user_one",
"name" => "Ben",
"email" => "ben@example.com",
"location" => "Egypt");
$profile->set_data($data);
echo $profile->output();Output:
<h1>user_one profile</h1>
<p><b>Name:</b> Ben</p>
<p><b>Email:</b> ben@example.com</p>
<p><b>Location:</b> Egypt</p>The returned html string contains all the values instead the placeholders.