PHP读取文件_2014.5.26的总结

时间:2014-05-28 00:45:32   收藏:0   阅读:305

1、PHP部分文件操作函数

  (1)  fopen 打开文件函数

      fopen (路径和文件名,打开方式);

  (2)  fread 读取文件内容

      fread (打开的文件,结束位置);

  (3)  filesize 读取文件大小,字节为计量单位

      filesize (路径和文件名);

  (4)  fwrite 写入文件内容

      fwrite (路径和文件名,写入的内容);

  (5)  fclose 关闭打开的文件

       close (路径和文件名);

  

    例:

    <?php

      $arr = array(array("新闻标题222","新闻内容222"),array("新闻标题333","新闻内容3333"));

      foreach($arr as $id=>$value){

          $fp = fopen("tmp.htm","r");

          str = fread($fp,filesize("tmp.htm"));

         fclose($fp);  

       $title = $value[0];   

          $content = $value[1];  

        $path = $id.".html";  

        $str = str_replace("{title}",$title,$str);  

          $str = str_replace("{content}",$content,$str);

          $nfp = fopen($path,"w");

        fwrite($nfp,$str);  

       fclose($nfp);

    }

?>

 

2、unlink()  rmdir() 删除函数

    unlink() 删除文件函数  

        unlink(路径和文件名)

    rmdir() 删除目录函数

        rmdir(路径和目录名)

 

 

 

 

PHP读取文件_2014.5.26的总结,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!