Php and html separation program
<? Php
// QQ: 695703951, I don't know the master's brother. I have some personal instructions. Learn fast...
Class fc_view{
Var $ fc_dir;// Specify the Directory
Var $ fc_file;// View file
Var $ fc_aval = array ();// Array
Var $ fc_lemark = '{';// You can change the flag on the left, for example, #.
Var $ fc_rimark = '}';// Right mark
// Specify the Template directory
Function dir ($ d){
$ This-> fc_dir = $ d;
If (file_exists ($ this-> fc_dir )){// Check whether a directory exists. If the directory is false, return to the upper-level Directory.
$ This-> fc_dir = dirname ($ PATH). $ d .'/';
} Else {
$ This-> fc_dir = '../'. dirname ($ PATH). $ d .'/';
}
}
// Specify the template file
Function file ($ f){
$ This-> fc_file = $ f;
}
Function ophtm ($ var){
$ File = @ file_get_contents ($ this-> fc_dir. $ this-> fc_file) or die ("not found :".
$ This-> fc_dir. $ this-> fc_file. "file");
Foreach ($ var as $ key => $ val){
$ File = str_replace ($ this-> fc_lemark. $ key. $ this-> fc_rimark, $ val, $ file );// Replace
}
Print $ file;
}
}
?>
Use
-------------------------------------------------------
Copy the PHP content to the clipboard.
PHP code:
<? Php
Include ('Common/fc_view.php ');// Run the specified file. It is the template file.
$ View = new fc_view ();// Class
$ View-> dir ('htmview ');// Template directory
$ View-> file('index.html ');// Template file
$ Var = array ();// Specify the array;
$ Var ['title'] = "title ";// Replace {title} in the html file}
$ Var ['main'] = "sharing... you can use it to learn. <br> tracing the Moon <br> ";// Replace {main} in the html file}
If (file_exists ('index. Php1')){
$ Var ['hei'] = "found";
} Else {
$ Var ['hei'] = "no file found";
}
$ View-> ophtm ($ var );// Output Template
?>
-------------------------------------------------------
-------------------------------------------------------
HTML file
-------------------------------------------------------
Copy the PHP content to the clipboard.
PHP code:
<Html>
<Head>
<Title> {title} </title>
</Head>
<Body>
{Main}
{Hehe}
</Body>
</Html>