Home > php教程 > php手册 > PHP之静态HTML

PHP之静态HTML

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:51:32
Original
1004 people have browsed it

静态HTML和从数据库里读取内容的动态页相比一直都有其不可替换的良好表现。在空间不做为第一考虑因素的时候,静态HTML显示更加适用。

PHP生成静态页,我总结了下有以下两个方法:

[php] 
$src = './index.tpl'; 
 
$content = file_get_content($src); 
$content = str_replace('{title}' , '标题' , $content); 
//相同替换 
$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}
 
 

第二两种就相对简单多了

[php] 
ob_start(); 
 
$top_id = 34; 
require './index.php'; 
 
ob_end_clean(); 
 
/**www.2cto.com
 *在index.php 可以将$top_id做为参数;因为这个是可以传递到index.php这个页面的。
 *然后在index.php里写入生成HTML的代码。即不需要替换也可以生成HTML;
 */ 


作者:tomyjohn
Related labels:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template