Join Up!
96807 members and counting!

 
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links 
search for in the  
previousfgetcsvfgetssnext
Last updated: Tue, 29 Oct 2002
view the printer friendly version or the printer friendly version with notes or change language to Czech | Finnish | German

fgets

(PHP 3, PHP 4 )

fgets -- Obtiene una línea del fichero apuntado

Descripción

string fgets ( int fp, int length)

Devuelve una cadena de como mucho length - 1 bytes leidos del fichero apuntado por fp. La lectura acaba cuando son leidos length - 1 bytes, cuando se llega a una nueva línea (el caracter de nueva línea se incluye en el valor devuelto), o cuando se llega a un EOF (lo que ocurra primero).

Si ocurre un error, devuelve FALSE.

Fallos Comunes:

Los que hayan usado la semantica de 'C' de la función fgets deben darse cuenta de la diferencia que hay en como el EOF es devuelto por esta función.

El apuntador al fichero debe ser válido, y debe apuntar a un fichero abierto con éxito con fopen(), popen(), o fsockopen().

A continuación un ejemplo sencillo:

Ejemplo 1. Leyendo un fichero línea por línea

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

Ver también fread(), fopen(), popen(), fgetc(), y fsockopen().

User Contributed Notes
fgets
add a note about notes
There are no user contributed notes for this page.
previousfgetcsvfgetssnext
Last updated: Tue, 29 Oct 2002
Copyright © 2001, 2002 The PHP Group
All rights reserved.
This mirror generously provided by: http://phpbuilder.com/
Last updated: Thu Oct 31 18:34:28 2002 EST