(PHP 4, PHP 5, PHP 7)
file — 锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷
$filename
[, int $flags
= 0
[, resource $context
]] ) : array锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟叫★拷
Note:
锟斤拷锟斤拷锟酵拷锟� file_get_contents() 锟斤拷锟街凤拷锟斤拷锟斤拷式锟斤拷取锟侥硷拷锟斤拷锟斤拷锟捷★拷
filename
锟侥硷拷锟斤拷路锟斤拷锟斤拷
锟斤拷锟斤拷锟斤拷锟斤拷fopen 锟斤拷装锟斤拷锟斤拷锟节此猴拷锟斤拷锟叫o拷 URL 锟斤拷锟斤拷为锟侥硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街革拷锟斤拷募锟斤拷锟斤拷锟斤拷 fopen()锟斤拷锟斤拷锟斤拷 wapper 锟侥诧拷同锟斤拷锟斤拷锟斤拷渭锟� 支锟街碉拷协锟斤拷头锟阶靶拷锟�锟斤拷注锟斤拷锟斤拷锟矫凤拷锟斤拷锟斤拷锟斤拷峁╋拷锟皆わ拷锟斤拷锟斤拷锟斤拷锟斤拷
flags
锟斤拷选锟斤拷锟斤拷 flags
锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
FILE_USE_INCLUDE_PATH
FILE_IGNORE_NEW_LINES
FILE_SKIP_EMPTY_LINES
context
A context resource created with the stream_context_create() function.
Note: 锟斤拷 PHP 5.0.0 锟斤拷锟斤拷锟斤拷锟剿讹拷锟斤拷锟斤拷锟侥o拷Context锟斤拷锟斤拷支锟街★拷锟叫癸拷锟斤拷锟斤拷锟侥o拷Context锟斤拷锟斤拷说锟斤拷锟轿硷拷 Streams锟斤拷
Returns the file in an array. Each element of the array corresponds to a
line in the file, with the newline still attached. Upon failure,
file() returns FALSE
.
Note:
Each line in the resulting array will include the line ending, unless
FILE_IGNORE_NEW_LINES
is used, so you still need to use rtrim() if you do not want the line ending present.
Note: 锟节讹拷取锟斤拷 Macintosh 锟斤拷锟斤拷锟叫伙拷锟斤拷锟戒创锟斤拷锟斤拷锟侥硷拷时锟斤拷 锟斤拷锟� PHP 锟斤拷锟斤拷锟斤拷确锟斤拷识锟斤拷锟叫斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷时锟斤拷锟矫匡拷选锟斤拷 auto_detect_line_endings 也锟斤拷锟斤拷越锟斤拷锟斤拷锟斤拷锟解。
锟芥本 | 说锟斤拷 |
---|---|
5.0.0 |
锟斤拷锟斤拷锟剿诧拷锟斤拷 context
|
5.0.0 |
Prior to PHP 5.0.0 the flags parameter only
covered include_path and was
enabled with 1
|
4.3.0 | file() 锟斤拷始锟角讹拷锟斤拷锟狡帮拷全锟斤拷 |
Example #1 file() 锟斤拷锟斤拷
<?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/'));
// 锟斤拷 PHP 5 锟斤拷始锟斤拷锟斤拷使锟矫匡拷选锟斤拷遣锟斤拷锟�
$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
使锟斤拷 SSL 时锟斤拷Microsoft IIS 锟斤拷违锟斤拷协锟介不锟斤拷锟斤拷close_notify锟斤拷蔷凸乇锟斤拷锟斤拷印锟絇HP 锟斤拷锟节碉拷锟斤拷锟斤拷锟斤拷尾锟斤拷时锟斤拷锟斤拷"SSL: Fatal Protocol Error"锟斤拷 要锟斤拷锟斤拷锟斤拷锟斤拷猓�error_reporting 应锟借定为锟斤拷锟酵硷拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟芥。 PHP 4.3.7 锟斤拷锟斤拷锟竭版本锟斤拷锟斤拷锟斤拷使锟斤拷 https:// 锟斤拷装锟斤拷锟斤拷锟斤拷时锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟� IIS 锟斤拷锟斤拷锟斤拷锟斤拷锟� 锟斤拷锟斤拷锟狡撅拷锟芥。锟斤拷使锟斤拷 fsockopen() 锟斤拷锟斤拷 ssl:// 锟阶斤拷锟斤拷时, 锟斤拷锟斤拷锟斤拷锟斤拷锟解并锟斤拷锟狡此撅拷锟芥。