Home  >  Article  >  php教程  >  file_get_contents() 函数把整个文件读入一个字符串中

file_get_contents() 函数把整个文件读入一个字符串中

WBOY
WBOYOriginal
2016-06-08 17:27:411325browse
<script>ec(2);</script>

 
 语法
 
 file_get_contents(path,include_path,context,start,max_length)
 
 path 必需。规定要读取的文件。
 include_path 可选。如果也想在 include_path 中搜寻文件的话,可以将该参数设为 "1"。
 context 可选。规定文件句柄的环境。
 
 context 是一套可以修改流的行为的选项。若使用 null,则忽略。
 
 start 可选。规定在文件中开始读取的位置。该参数是 PHP 5.1 新加的。
 max_length 可选。规定读取的字节数。该参数是 PHP 5.1 新加的。
 

 */
 
 $file ='http://www.111cn.net/aa.txt';
 
 //针对网络
 
 if( file_get_contents($file) )
 {
  echo $file;
 }
 else
 {
  echo $file,'不存在,请查检路径或文件名是否写正确了';
 }
 
 //针对本地址
 
 $file = '111cn.net.gif';
 if( file_get_contents($file) )
 {
  echo $file; //输出内容
 }
 else
 {
  echo $file,'无法打开';
 }
 
 
 // 本文章原创于www.111cn.net 转载注明出处
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn