PHP is the world's smallest and simplest template engine ------ Pain (normal version). Unlike smarty, all variables are included in the {@}, which helps you understand the template engine. Package download
Pain. php
Copy codeThe code is as follows:
Class Pain
{
Public $ var = array ();
Public $ tpl = array ();
// This is the method to assign vars to the template
Public function assign ($ variable, $ value = null)
{
$ This-> var [$ variable] = $ value;
}
Public function display ($ template_name, $ return_string = false)
{
// First find whether the tmp file in tmp dir exists.
If (file_exists ("tmp/temp_file.php "))
{
Unlink ("tmp/temp_file.php ");
}
Extract ($ this-> var );
$ Tpl_content = file_get_contents ($ template_name );
$ Tpl_content = str_replace ("{@"," $ Tpl_content = str_replace ("@}", "?> ", $ Tpl_content );
// Create a file in the/tmp dir and put the $ tpl_contentn into it, then
// Use 'include 'method to load it!
$ Tmp_file_name = "temp_file.php ";
// $ Tmp is the handler
$ Tmp = fopen ("tmp/". $ tmp_file_name, "w ");
Fwrite ($ tmp, $ tpl_content );
Include "tmp/". $ tmp_file_name;
}
}
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.