php的文件操作(day2)

/**

  • 打开文件fopen
  • 读写文件 fgets,fwrite
  • 关闭文件fclose
  • 1附加函数feof是否已经到末尾
  • 2一次将所有文件读出file_get_contents($filename)
  • 3使用file_put_content($filename)
    */
    //按行读取`
// $fp=fopen("D:/VM12/hello.txt","r");
// while(!feof($fp)){
//     $line=fgets($fp);
//     $line=str_replace("\n","<br/>",$line);
//     echo $line;
// }
// fclose($fp);
//写入
// $fp=fopen("D:/VM12/hello.txt","a");
// fwrite($fp,"\n2222");
// fclose($fp);

// header("content-type:text/html;charset='gbk'");
// $content=file_get_contents("D:/VM12/hello.txt");
// $content=iconv("GBK","UTF-8",$content);
// $list=explode("\n",$content);
// print_r($list);
//使用file_get_contents可以访问网页;

// $content=file_get_contents("http://www.woniunote.com");
// echo $content;

//网页爬虫的设计思路
/**

  • 编码转义,utf三字节处理,gbk两字节处理
    */
/ $content=iconv("UTF-8","GBK","\n勒布朗詹姆斯");
// file_put_contents("D:/VM12/hello.txt",$content,FILE_APPEND);
//读取csv文件逗号分隔符文件并且解析为二维数组
// $content=file_get_contents("D:/VM12/hello.txt");
// $rows=explode("\n",$content);
// $list=array();
// for($i=1;$i<count($rows);$i++){
//     $temp=explode(",",$row[1]);
//     array_push($list,$temp);
// }
// print_r($list);

//使用php模拟tail-f实时查看文件内容
//获取当前文件指针位置ftell
//直接将文件指针指向某一个位置

/ $fp=fopen("filename");
// fseek($fp,25);
// while($line=fgets($fp)){
//     echo $line ."<br/>";
// }
// fclose($fp);
// set_time_limit(0);
// $pos=0;
// while(true){
//     $fp=fopen("test.txt","r");
//     fseek($fp,$pos);
//     while($line=fgets($fp)){
//         $line=iconv("GBK","utf-8",$line);
//         echo $line ."<br/>";
//     }
//     $pos=ftell($fp);
//     fclose($fp);
//     ob_flush();
//     flush();
//     sleep(2);
// }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值