文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>php生成html页面实现代码

php生成html页面实现代码

时间:2010-11-21  来源:秩名

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

<?php   $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 个字节时就会停止读取文件,视乎先碰到哪种情况。

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


更多详细内容请查看:http://www.hackline.net/a/special/wzjs/wzbc/php/2010/1121/7043.html

缓存输出 ob_end_clean ob_start ob_get_length ob_get_contents函数

<?php   $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():这个比较重要,只有使用了这个函数后,缓冲区里的内容才会读取出来

 

标签分类:

相关阅读 更多 +
排行榜 更多 +
夕鸟

夕鸟

生活实用 下载
partyplay

partyplay

聊天通讯 下载
婚礼纪

婚礼纪

生活实用 下载