Função PHP fgets()
❮ Referência do sistema de arquivos PHPExemplo
Leia uma linha do arquivo aberto:
<?php
$file = fopen("test.txt","r");
echo fgets($file);
fclose($file);
?>
Definição e uso
A função fgets() retorna uma linha de um arquivo aberto.
Sintaxe
fgets(file, length)
Valores de parâmetro
Parameter | Description |
---|---|
file | Required. Specifies the open file to return a line from |
length | Optional. Specifies the number of bytes to read. Reading stops when length-1 bytes have been reached, or when a new line occurs, or on EOF. If no length is specified, it reads until end of the line |
Detalhes técnicos
Valor de retorno: | Uma única linha lida do arquivo em caso de sucesso, FALSE em EOF ou erro |
---|---|
Versão do PHP: | 4.0+ |
Binário Seguro: | Sim, no PHP 4.3 |
Mais exemplos
Exemplo
Leia o arquivo aberto, linha por linha:
<?php
$file = fopen("test.txt","r");
while(! feof($file))
{
echo fgets($file). "<br />";
}
fclose($file);
?>
❮ Referência do sistema de arquivos PHP