Hello, I am trying to extract information from a txt file with PHP, for example:
Line 1: Luis Juarez
Line 2: Paco Mendoza
Line 3: Pepe Suarez
They helped me before with this sentence
$arc = fopen('archivos/'.$nombre,"r");
while(! feof($arc)) {
$Nombre = substr(fgets($arc), 0, 4);
$Apellido = substr(fgets($arc), 6, 10);
echo $Nombre;
echo "<brs>";
echo $Apellido;
echo "<br>";
}
fclose($arc);
The problem is that every time it is executed fgets()
it sends me to the next line and prints Luis Mendoza on the screen when Luis Juarez should print, could someone help me with the solution Thank you very much in advance
You must store the line returned by
fgets
in a variable, and then process it. It is also better to split the line at the blank character' '
, usingexplode
because the name can have any number of characters.