(PHP 4, PHP 5, PHP 7)
file — �������ļ�����һ��������
$filename
[, int $flags = 0
[, resource $context
]] ) : array�������ļ�����һ�������С�
Note:
�����ͨ�� file_get_contents() ���ַ�����ʽ��ȡ�ļ������ݡ�
filename�ļ���·����
��������fopen ��װ�����ڴ˺����У� URL ����Ϊ�ļ������������ָ���ļ������ fopen()������ wapper �IJ�ͬ������μ� ֧�ֵ�Э��ͷ�װЭ����ע�����÷�������ṩ��Ԥ���������
flags
��ѡ���� flags ����������һ������������
FILE_USE_INCLUDE_PATH
FILE_IGNORE_NEW_LINES
FILE_SKIP_EMPTY_LINES
contextA context resource created with the stream_context_create() function.
Note: �� PHP 5.0.0 �������˶������ģ�Context����֧�֡��й������ģ�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_LINESis 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 ��ʼ����ʹ�ÿ�ѡ��Dz���
$trimmed = file('somefile.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
?>
ʹ�� SSL ʱ��Microsoft IIS ��Υ��Э�鲻����close_notify��Ǿر����ӡ�PHP ���ڵ�������β��ʱ����"SSL: Fatal Protocol Error"�� Ҫ��������⣬error_reporting Ӧ�趨Ϊ���ͼ��������������档 PHP 4.3.7 �����߰汾������ʹ�� https:// ��װ������ʱ����������� IIS ��������� �����ƾ��档��ʹ�� fsockopen() ���� ssl:// ����ʱ, ���������Ⲣ���ƴ˾��档