zoukankan      html  css  js  c++  java
  • 009PHP文件处理——文件处理 file_get_contents file_put_contents fgetc fgets fgetss

    <?php
    /**
     * 文件处理 file_get_contents  file_put_contents  fgetc  fgets  fgetss
     */
    
    //fgetc() 传入文件操作句柄。每次获得一个字符:
    /*$file=fopen('a.txt','r');
    echo fgetc($file);
    echo fgetc($file);*/
    
    /*fgets() 传入文件句柄 获取一行字符,默认是1024个字节。如果传入,就按他传入的:length-1个
     * */
    //feof()判断文件是否读取结束,指针。
    /*$file=fopen('a.txt','r');
    while (!feof($file)){
        echo fgets($file);
    }*/
    
    //fgetss() 每次读取一行内容,过滤掉HTML 和PHP 标签。第三个参数指定保留的标签:
    /*$file=fopen('a.php','r');
    while (!feof($file)) {
        echo fgetss($file,1024,"<div><style>");
        //保留a.php文件中的div和style标签,其他过滤掉。
    }*/
    
    //file_get_contents() 一次性读取文件内容
    //  他是:fopen()  fread()  fclose的集合体,他也可以读取远程文件
    /*$contents=file_get_contents("a.php");
    echo $contents;*/
    //读取远程文件
    /*$contents=file_get_contents("https://www.baidu.com/");
    echo $contents;*/
    
    //file_put_contents()  一次性写入文件内容
    //  创建文件存储内容:相当于,fopen()  fwrite()  fclose()
    /*sleep(2);//等待3秒加载以下内容:
    file_put_contents('t.txt','好好学习,天天向上');*/
    
    //打开远程sina网址,并存储到sina.html中
    $sina=file_get_contents('http://www.sina.com.cn/');
    file_put_contents('sina.html',$sina);
    

      

  • 相关阅读:
    兼容性问题
    【浏览器渲染原理】 渲染树和页面渲染
    leetcode153. 寻找旋转排序数组中的最小值
    leetcode162. 寻找峰值
    各种常量池
    leetcode137. 只出现一次的数字 II
    leetcode136. 只出现一次的数字
    leetcode133. 克隆图
    ClassLoader分类
    overload和override
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8277086.html
Copyright © 2011-2022 走看看