Package download
pain.php
Copy Code code as follows:
<?php
Class Pain
{
Public $var =array ();
Public $tpl =array ();
This is the assign VARs to the template
Public function assign ($variable, $value =null)
{
$this->var[$variable]= $value;
}
Public function display ($template _name, $return _string=false)
{
The 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 ("{@", "<?php echo", $tpl _content);
$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;
}
}
?>
test.php
Copy Code code as follows:
<?php
Require_once "pain.php";
$pain =new pain ();
$songyu = "Songyu nb";
$zhangyuan = "Zhangyuan sb";
$pain->assign ("Songyu", $songyu);
$pain->assign ("Zhangyuan", $zhangyuan);
$pain->display ("new_file.html");
?>
New_file.html
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en"
"Http://www.w3.org/TR/html4/strict.dtd" >
<meta http-equiv=" Content-type "content=" text/ html Charset=utf-8 "/>
<title>new_file</title>
<body>
{@ $songyu @}< ;br/>
{@ $zhangyuan @}
</body>