Página web de Victor Reyes Lucas

Leer un archivo .txt línea a línea en PHP con fgets()

logo php Leer un archivo .txt línea a línea en PHP con fgets()Para leer un archivo .txt línea a línea en PHP vamos a utilizar la función fgets(). Por ejemplo si queremos leer línea por línea el archivo 1.txt que se encuentra ubicado en la misma carpeta que el archivo .php, tenemos que escribir en el archivo PHP:

<?php
$file = fopen(“1.txt”, “r”) or exit(“Unable to open file!”);
//Output a line of the file until the end is reached
while(!feof($file))
{
echo fgets($file). “<br />”;
}
fclose($file);
?>

VN:F [1.9.14_1148]
Rating: 0.0/10 (0 votes cast)

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos necesarios están marcados *

*


*

Puedes usar las siguientes etiquetas y atributos HTML: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

CommentLuv badge