array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.stream-get-line.php', 1 => 'stream_get_line', ), 'up' => array ( 0 => 'ref.stream.php', 1 => 'Stream 函数', ), 'prev' => array ( 0 => 'function.stream-get-filters.php', 1 => 'stream_get_filters', ), 'next' => array ( 0 => 'function.stream-get-meta-data.php', 1 => 'stream_get_meta_data', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/stream/functions/stream-get-line.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 5, PHP 7, PHP 8)
stream_get_line — 从资源流里读取一行直到给定的定界符
从给定的资源流里读取一行。
当读取到 length
个字节数就结束,或者当在读取的非空字符串中发现 ending
(不包含到返回值里)也结束,又或者遇到了 EOF 也结束(总之以上条件中哪个先出现就以哪个为准)。
这个函数与 fgets() 几乎是相同的,唯一的区别是在这个函数里面允许指定行尾的定界符,而不是使用标准的 \n, \r 还有 \r\n ,并且返回值中不包含定界符。(翻译注:也可以把 \n 等作为定界符传入 ending
)
stream
一个有效的文件句柄。
length
需要从句柄中读取的最大字节数。不支持负值。
0
表示默认的套接字块大小(socket chunk size),即
8192
字节。
ending
可选参数,字符串定界符。
返回一个字符串,该字符串的内容根据 length
字节数从 stream
里读取, 或者在失败时返回 false
。