Static HTML for PHP_PHP Tutorial

WBOY
Release: 2016-07-13 17:53:29
Original
879 people have browsed it

Static HTML has always had irreplaceable performance compared to dynamic pages that read content from the database. When space is not the first consideration, static HTML display is more suitable.

PHP generates static pages. I have summarized the following two methods:

[php]
$src = './index.tpl';

$content = file_get_content($src);
$content = str_replace('{title}' , 'title' , $content);
//Same replacement
$content = str_replace( ... );

$fp = fopen('./index.html' , 'w') or die('can not open file');
fputs($fp, $content);
fclose($fp);
unset($fp);
index.tpl

[html]

{title}

The second two are relatively simple

[php]
ob_start();

$top_id = 34;
require './index.php';

ob_end_clean();

/**www.2cto.com
*You can use $top_id as a parameter in index.php; because this can be passed to the index.php page.
*Then write the code to generate HTML in index.php. That is, HTML can be generated without replacement;
​*/


Author: tomyjohn

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478036.htmlTechArticleStatic HTML has always had irreplaceable performance compared with dynamic pages that read content from the database. When space is not the first consideration, static HTML display is more suitable. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!