PHP dynamic variable static principle _php Tutorial

Source: Internet
Author: User
With PHP output static page method, as I know, there are 2 kinds, one is the use of template technology, the other is the OB series function. Both methods look the same, but in fact, they are different.

The first type: using templates。 PHP is now a template can be said to be many, there are powerful smarty, there are easy-to-use smarttemplate and so on. Each of these templates has a function to get the output content. The way we generate static pages is to take advantage of this function. The advantage of this method is that the code is clear and readable.

Here I use Smarty as an example to show how to generate static pages
Copy CodeThe code is as follows: Require (' smarty/smarty.class.php ');
$t = new Smarty;
$t->assign ("title", "Hello world!");
$content = $t->fetch ("templates/index.htm");
Here the fetch () is the function that gets the output content, now inside the $content variable, is to display the content
$fp = fopen ("archives/2005/05/19/0001.html", "w");
Fwrite ($fp, $content);
Fclose ($FP);
?>
The second method of: Use the functions of the OB series. The function used here is mainly Ob_start (), Ob_end_flush (), Ob_get_content (), where Ob_start () is the meaning of opening the browser buffer, after opening the buffer, all non-file header information from the PHP program will not be sent, Instead, it is saved in the internal buffer until you use Ob_end_flush (). The most important function here is ob_get_contents (), the function of which is to get the contents of the buffer, equivalent to the fetch () above, the same reason. Code:
Copy CodeThe code is as follows: Ob_start ();
echo "Hello world!";
$content = Ob_get_contents ();//Get all the contents of the PHP page output
$fp = fopen ("archives/2005/05/19/0001.html", "w");
Fwrite ($fp, $content);
Fclose ($FP);
?>

http://www.bkjia.com/PHPjc/317259.html www.bkjia.com true http://www.bkjia.com/PHPjc/317259.html techarticle with PHP output static page method, as I know, there are 2 kinds, one is the use of template technology, the other is the OB series function. Both methods look the same, but actually ...

  • 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.