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);
    

      

  • 相关阅读:
    react 中文文档案例三 (开关按钮)
    react 中文文档案例二 (头像时间)
    react 中文文档案例一 (倒计时)
    韩昊 20190905-2 博客作业
    韩昊 20190905-3 命令行和控制台编程
    bug的状态
    冒泡排序
    python简单实现自动化
    如何写好测试用例——慕课网
    快速搭建springboot项目
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8277086.html
Copyright © 2011-2022 走看看