Home >Backend Development >PHP Tutorial >Static HTML for PHP_PHP Tutorial
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]
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;
*/