不正狼 发表于 2017-3-22 11:49:41

PHP file_get_contents() 函数

  


PHP Filesystem 函数



定义和用法

file_get_contents() 函数把整个文件读入一个字符串中。
和 file() 一样,不同的是 file_get_contents() 把文件读入一个字符串。
file_get_contents() 函数是用于将文件的内容读入到一个字符串中的首选方法。如果操作系统支持,还会使用内存映射技术来增强性能。

语法

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 新加的。


说明

对 context 的支持是 PHP 5.0.0 添加的。



提示和注释

注释:本函数可安全用于二进制对象。



例子

<?php
print_r(file("test.txt"));
?>
输出:

Array
(
=> Hello World. Testing testing!
=> Another day, another line.
=> If the array picks up this line,
=> then is it a pickup line?
)


PHP Filesystem 函数
页: [1]
查看完整版本: PHP file_get_contents() 函数