zoukankan      html  css  js  c++  java
  • 014PHP文件处理——文件指针控制fseek rewind ftell feof fpassthru

    <?php
    /**
     * 文件指针控制fseek  rewind  ftell  feof  fpassthru
     */
    
    //feof()判断文件读取是否超出文件长度
    /*$file = fopen('a.txt', 'r');
    fread($file, filesize('a.txt')+ 1);
    echo intval(feof($file));//feof()判断文件读取是否超出文件长度,超出返回1*/
    
    /*$file = fopen('a.txt', 'r');
    echo fgets($file);//获取文件第一行的内容
    echo ftell($file);//获取当前指针所在的位置*/
    
    /*$file = fopen('a.txt', 'r');
    fseek($file,6);//移动文件指针到第6个字节
    echo ftell($file);
    
    fseek($file,50,SEEK_CUR);//从当前指针在增加50个字节
    
    fseek($file,100,SEEK_END);//从文件末尾,增加100个字节*/
    $file = fopen('a.txt', 'r');
    fseek($file,6);
    rewind($file);//归位指针
    echo ftell($file);//输出:0
    fclose($file);

    Fpassthru()  输出文件指针处的所有剩余数据

      

  • 相关阅读:
    c# 运算符 ? ??
    c# linq <未完>
    javasript this
    python3 闭包(一)
    dom 中的换行符
    (转)关于 awk 的 pattern(模式)
    linux note(1)
    python sqlite3
    python 特殊方法
    Go Example--锁
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8311607.html
Copyright © 2011-2022 走看看