Home > php教程 > php手册 > 二种php生成html页面实现代码

二种php生成html页面实现代码

WBOY
Release: 2016-06-13 10:00:09
Original
994 people have browsed it

二种php教程生成html页面实现代码

利用fopen fread  fwrite fcolse打开文件形式

$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 ("写入模板失败!");
}
}
?>

php读取文件,fread是用来读取用fopen打开的文件内容的,下面我们就来看看fread与gets 实例教程吧.

定义和用法
fread() 函数读取文件(可安全用于二进制文件)。

语法
fread(file,length)参数 描述
file 必需。规定要读取打开文件。
length 必需。规定要读取的最大字节数。

说明
fread() 从文件指针 file 读取最多 length 个字节。该函数在读取完最多 length 个字节数,或到达 eof 的时候,或(对于网络流)当一个包可用时,或(在打开用户空间流之后)已读取了 8192 个字节时就会停止读取文件,视乎先碰到哪种情况。

$file = fopen("test.txt","r");
fread($file,filesize("test.txt"));
fclose($file);
?>


更多详细内容请查看:http://www.bKjia.c0m/phper/18/753bc9c01fa5a721a81c63887ddccb47.htm

缓存输出 ob_end_clean ob_start ob_get_length ob_get_contents函数

$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);
?>


三个函数吧:"ob_start()、ob_end_clean()、ob_get_contents()"

ob_start():是打开缓冲区的,就是要把您需要生成的静态文件的内容缓存在这里;
ob_get_contents():是读出缓冲区里的内容,下面有代码为例;
ob_end_clean():这个比较重要,只有使用了这个函数后,缓冲区里的内容才会读取出来

更多详细内容请查看:http://www.bKjia.c0m/phper/php-cy/35433.htm

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