Php and html separation program

Source: Internet
Author: User
Tags php and

 

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>
Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.