Home  >  Article  >  php教程  >  php fgets 函数

php fgets 函数

WBOY
WBOYOriginal
2016-06-13 11:17:221332browse

php fgets 函数  

fgets
( PHP 4中, PHP 5中)

fgets -获取线从文件指针

描述
字符串fgets (资源$处理[摘要$长度] )
得到线从文件指针。

参数

把柄
文件指针必须有效,必须指向一个文件成功打开fopen ( )或者fsockopen ( ) (和尚未关闭fclose ( ) ) 。

长度
读时结束长度- 1字节被读取,就换行(其中包括在返回值) ,或EOF分析(以先到者为准) 。如果没有指定长度,将继续读流直至到达行末。

注:在此之前PHP 4.3.0起,漏报,将承担1024年的线的长度。如果大多数按照该文件中都大于8KB ,更有效的资源为您的脚本来指定最大行的长度。



返回值
返回一个字符串的长度最多- 1字节读取文件指出,由处理。

如果出现错误,则返回FALSE 。

修改

版本说明
4.3.0 fgets ( )现在是二进制安全
4.2.0长度参数是可选的

看个实例:

$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php ftp函数文件上传Next article:php filegroup 函数