Home > php教程 > php手册 > body text

怎样用PHP生成html文件

WBOY
Release: 2016-06-21 09:06:55
Original
1683 people have browsed it

生成html

怎样用PHP生成html文件?
总结一
贴子发出后,得到网友们的热烈响应和帮助,为回报各位村民,特把有效回贴整理出
1,Matrix@Two_Max的发贴:
$fp = fopen ("templets.html","a");
if ($fp){
$fup = fread ($fp,filesize("templets.html"));
$fp2 = fopen ("html.shtml","w");
if ($fwrite ($fp2,$fup)){
$fclose ($fp);
$fcolse ($fp2);
die ("写入模板成功");
} else {
fclose ($fp);
die ("写入模板失败!");
}
}
?>
简单的将模板写进一个文件中存为html.html


2,Matrix@Two_Max的发贴:
这是模板文件,你需要在服务器上提供templets.html这样一个模板文件

没有模板谈何生成?

当然,你也可以这样生成一个静态页面。只是少了一步打开模板,替换内容的过程
$content = "这是一个静态生成网页的测试文件,文件名为html.html";
$fp = fopen ("html.shtml","w");
if (fwrite ($fp,$content)){
fclose ($fp);
die ("写入模板成功");
} else {
fclose ($fp);
die ("写入模板失败!");
}
?>


3,rebol的发贴:
$s_fname = "93e.php";
$o_fname = "93e.htm";
ob_end_clean();
ob_start();
include($s_fname);
$length = ob_get_length();
$buffer = ob_get_contents();
$buffer = eregi_replace("r","",$buffer);
ob_end_clean();

$fp = fopen($o_fname,"w+");
fwrite($fp,$buffer);
fclose($fp);
?>

这样就可以把
93e.php转化为静态的HTML文件了
要注意的是待转换的文件里不能有
ob_end_clean();和 ob_start();语句。
且目录要有写权限。
 



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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template