PHP读取文件所有内容到字符串 file_get_contents

来源:互联网 发布:hadoop书籍 知乎 编辑:程序博客网 时间:2024/05/21 10:10

string file_get_contents ( string $filename [, bool $use_include_path [, resource $context [, int $offset [, int $maxlen ]]]] )

  将文件读入一个字符串。第三个参数$context可以用来设置一些参数,比如访问远程文件时,设置超时等等。

  另外,file_get_contents相对于以上几个函数,性能要好得多,所以应该优先考虑使用file_get_contents。但是readfile貌似比file_get_contents性能好一点(?),因为它不需要调用fopen。


<?php     $ctx = stream_context_create(array(         'http' => array(             'timeout' => 1    //设置超时            )         )     );     echo file_get_contents("http://www.baidu.com/", 0, $ctx); ?>
原创粉丝点击