当读入一个巨大的字符串的时候不能使用file_get_contents(‘文件名’)

应该 使用fopen(’文件名’,’r’)

feof(‘文件名’)  //判断是否读到了文件结尾

***********************************

fgets(‘文件名’)   //从文件里面读取一行

*********************************

str_replace(被替换的字符,替换的字符,操作对象)

********************************

fwrite(输出的文件名,输出的内容)

**************************************

fcolse(文件名)   //关闭文件

**************************************

 

例子:

//生成静态页
        $id=mysql_insert_id();
        $htmlFile='news_id',$id.'.html';
        $tpl_file=fopen('news.tpl','r');
        $html_file=fopen($htmlFile,'w');

        while(!feof($tpl_file)){
            $row_str=fgets($tpl_file);
            $row_str=str_replace('%title%',$title,$row_str);
            fwrite($html_file,$row_str);
        }
        fclose($tpl_file);
        fclose($html_file);
        header('content-type:text/html;charset=utf-8');
        echo "添加并生成静态页面成功";

posted on 2015-09-14 23:29  梦想的初衷  阅读(109)  评论(0编辑  收藏  举报