zoukankan      html  css  js  c++  java
  • readfile & file_get_contents异同

    记录一下:应用memcache时,准备把整个文件缓存到内存中,遇到了比较奇怪的事情,因为最初使用readfile来读取文件,结果这个函数返回一个字节数,而不是一个字符串,于是文件没办法再输出,最后使用file_get_contents解决问题。
     
    file_get_contents -- 将整个文件读入一个字符串
     
    说明
    string file_get_contents ( string filename [, bool use_include_path [, resource context [, int offset [, int maxlen]]]] )
    和 file() 一样,只除了 file_get_contents() 把文件读入一个字符串。将在参数 offset 所指定的位置开始读取长度为 maxlen 的内容。如果失败,file_get_contents() 将返回 FALSE。
     
    file_get_contents() 函数是用来将文件的内容读入到一个字符串中的首选方法。如果操作系统支持还会使用内存映射技术来增强性能。
     
    readfile -- 输出一个文件
     
    说明
     
    int readfile ( string filename [, bool use_include_path [, resource context]] )
    读入一个文件并写入到输出缓冲。
     
    返回从文件中读入的字节数。如果出错返回 FALSE 并且除非是以 @readfile() 形式调用,否则会显示错误信息。
     
    $file = readfile('./test.txt');
    echo $file;
    var_dump($file);
     
    $file = file_get_contents('./test.txt');
    echo $file;
    var_dump($file);
     
    输出:
     
    qweyrqiwueryqioweyrqioweru26
    int(26) 
    qweyrqiwueryqioweyrqioweru
    string(26) "qweyrqiwueryqioweyrqioweru"
  • 相关阅读:
    网站设计大访问量应用的解决方案
    粘贴剪辑版中的数据
    C#中DateTime
    汇总c#.net常用函数和方法集
    ASP.NET配置文件Web.config 详细解释
    URL验证
    把一个下拉框中的选项添加到另一个中
    显示年月日星期和(变动的)时间
    sqlserver 查询版本号
    FreeMarker(三)Map和List
  • 原文地址:https://www.cnblogs.com/yulei126/p/6786173.html
Copyright © 2011-2022 走看看