PHP  
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
search for in the  
<file_put_contentsfileatime>
Last updated: Mon, 16 Jul 2012

file

(PHP 3, PHP 4, PHP 5)

file -- 把整个文件读入一个数组中

说明

array file ( string filename [, int use_include_path [, resource context]] )

readfile() 一样,只除了 file() 将文件作为一个数组返回。数组中的每个单元都是文件中相应的一行,包括换行符在内。如果失败 file() 返回 FALSE

如果也想在 include_path 中搜寻文件的话,可以将可选参数 use_include_path 设为 "1"。

<?php
// 将一个文件读入数组。本例中通过 HTTP 从 URL 中取得 HTML 源文件。
$lines = file ('http://www.example.com/');
// 在数组中循环,显示 html 的源文件并加上行号。
foreach ($lines as $line_num => $line) {
   echo
"Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br>\n";
}
// 另一个例子将 web 页面读入字符串。参见 file_get_contents()。
$html = implode ('', file ('http://www.example.com/'));
?>

提示: 如果“fopen wrappers”已经被激活,则在本函数中可以把 URL 作为文件名来使用。请参阅 fopen() 函数来获取怎样指定文件名的详细信息以及支持 URL 协议的附录 L列表。

注: 返回的数组中每一行都包括了行结束符,因此如果不需要行结束符时还需要使用 trim() 函数。

注: 如果碰到 PHP 在读取文件时不能识别 Macintosh 文件的行结束符,可以激活 auto_detect_line_endings 的运行时配置选项。

注: 从 PHP 4.3.0 开始可以用 file_get_contents() 来将文件读入到一个字符串返回。

从 PHP 4.3.0 开始 file() 可以安全用于二进制文件。

注: Context 支持是 PHP 5.0.0 新加的。

参见 readfile()fopen()fsockopen()popen()file_get_contents()include()




<file_put_contentsfileatime>
 Last updated: Mon, 16 Jul 2012
 
Copyright © 2001-2005 The PHP Group
All rights reserved.
This unofficial mirror is operated at: http://manual.phpv.net/
Last updated: Thu Jul 7 19:13:47 2005 CST