(PHP 4, PHP 5, PHP 7)
fgets — ���ļ�ָ���ж�ȡһ��
$handle
[, int $length
] ) : string���ļ�ָ���ж�ȡһ�С�
handle�ļ�ָ���������Ч�ģ�����ָ���� fopen() �� fsockopen() �ɹ����ļ�(����δ�� fclose() �ر�)��
length
�� handle
ָ����ļ��ж�ȡһ�в����س������Ϊ length - 1
�ֽڵ��ַ������������з��������ڷ���ֵ�У���EOF �����Ѿ���ȡ�� length - 1
�ֽں�ֹͣ������������һ������������û��ָ��
length����Ĭ��Ϊ 1K������˵ 1024 �ֽڡ�
Note:
�� PHP 4.3 ��ʼ�����Ե� length ���еij��ȱ��ٶ�Ϊ 1024�������������ж�ȡ����ֱ���н���������ļ��еĴ�����ж����� 8KB�����ڽű���ָ������еij�����������Դ�ϸ�Ϊ��Ч��
��ָ�� handle ָ����ļ��ж�ȡ�� length - 1 �ֽں��ַ�����
����ļ�ָ����û�и������������ FALSE��
������ʱ���� FALSE��
| �汾 | ˵�� |
|---|---|
| 4.3.0 | fgets() ��ʼ�����ư�ȫ |
| 4.2.0 |
length ������Ϊ��ѡ��
|
Example #1 ���ж�ȡ�ļ�
<?php
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
while (($buffer = fgets($handle, 4096)) !== false) {
echo $buffer;
}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
}
fclose($handle);
}
?>
Note: �ڶ�ȡ�� Macintosh �����л����䴴�����ļ�ʱ�� ��� PHP ������ȷ��ʶ���н���������������ʱ���ÿ�ѡ�� auto_detect_line_endings Ҳ����Խ�������⡣
Note:
ϰ���� C ������ fgets() �����Ӧ��ע� EOF �����������صġ�