php-doc-en/reference/filesystem/functions/fgets.xml
Hartmut Holzgraefe 5b9fc29465 revision tags added
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@78496 c90b9560-bf6c-de11-be94-00142212c4b1
2002-04-17 06:45:35 +00:00

88 lines
2.6 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- splitted from ./en/functions/filesystem.xml, last change in rev 1.2 -->
<refentry id="function.fgets">
<refnamediv>
<refname>fgets</refname>
<refpurpose>Gets line from file pointer</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<methodsynopsis>
<type>string</type><methodname>fgets</methodname>
<methodparam><type>int</type><parameter>fp</parameter></methodparam>
<methodparam choice="opt"><type>int</type><parameter>length</parameter></methodparam>
</methodsynopsis>
<para>
Returns a string of up to length - 1 bytes read from the file
pointed to by fp. Reading ends when length - 1 bytes have been
read, on a newline (which is included in the return value), or on
EOF (whichever comes first). If no length is specified, the length
defaults to 1k, or 1024 bytes.
</para>
<para>
If an error occurs, returns &false;.
</para>
<para>
Common Pitfalls:
</para>
<simpara>
People used to the 'C' semantics of <function>fgets</function>
should note the difference in how <literal>EOF</literal> is returned.
</simpara>
<simpara>
The file pointer must be valid, and must point to a file
successfully opened by <function>fopen</function>,
<function>popen</function>, or
<function>fsockopen</function>.
</simpara>
<para>
A simple example follows:
<example>
<title>Reading a file line by line</title>
<programlisting role="php">
<![CDATA[
$fd = fopen ("/tmp/inputfile.txt", "r");
while (!feof ($fd)) {
$buffer = fgets($fd, 4096);
echo $buffer;
}
fclose ($fd);
]]>
</programlisting>
</example>
</para>
<note>
<simpara>
The <parameter>length</parameter> parameter became optional in PHP 4.2.0
</simpara>
</note>
<para>
See also <function>fread</function>, <function>fopen</function>,
<function>popen</function>, <function>fgetc</function>,
<function>fsockopen</function>, and
<function>socket_set_timeout</function>.
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->