93 lines
2.4 KiB
PHP
93 lines
2.4 KiB
PHP
<?php
|
|
$archivo = "formularios/registro.txt";
|
|
|
|
// Verifico si existe
|
|
if (file_exists($archivo)) {
|
|
/*
|
|
//Con file_get_contents
|
|
// Leo el contenido del archivo
|
|
$contenido = file_get_contents($archivo);
|
|
|
|
// Divide el contenido en líneas
|
|
$lineas = explode("\n", $contenido);
|
|
array_pop($lineas);// Borro la última línea vacia
|
|
//var_dump($lineas);
|
|
// Comienzo la tabla HTML
|
|
echo "<table border='1'>";
|
|
echo "<tr><th>Número</th><th>Nombre</th><th>Email</th><th>Ruta de Archivo</th></tr>";
|
|
|
|
// Itero sobre cada línea
|
|
$num=0;
|
|
foreach ($lineas as $linea) {
|
|
// Divido los datos de la línea utilizando el delimitador "/_/"
|
|
$datos = explode("/_/", $linea);
|
|
$num++;
|
|
// Muestra los datos en una fila de la tabla
|
|
echo "<tr>";
|
|
echo "<td>" . $num . "</td>"; // Número
|
|
echo "<td>" . $datos[0] . "</td>"; // Nombre
|
|
echo "<td>" . $datos[1] . "</td>"; // Email
|
|
echo "<td>" . $datos[2] . "</td>"; // Ruta de Archivo
|
|
echo "</tr>";
|
|
}
|
|
|
|
// Cierro la tabla HTML
|
|
echo "</table>";
|
|
} else {
|
|
echo "El archivo no existe.";
|
|
}
|
|
*/
|
|
|
|
// Con fgets
|
|
// Abrir el archivo en modo lectura
|
|
$gestor = fopen($archivo, "r");
|
|
|
|
|
|
|
|
// Comienzo la tabla HTML
|
|
echo "<table border='1'>";
|
|
echo "<tr><th>Número</th><th>Nombre</th><th>Email</th><th>Ruta de Archivo</th></tr>";
|
|
|
|
$num = 0;
|
|
|
|
// Iterar sobre cada línea del archivo
|
|
while (($linea = fgets($gestor)) !== false) {
|
|
|
|
// Dividir los datos de la línea utilizando el delimitador "/_/"
|
|
$datos = explode("/_/", $linea);
|
|
|
|
// Incrementar el número de fila
|
|
$num++;
|
|
|
|
// Mostrar los datos en una fila de la tabla
|
|
echo "<tr>";
|
|
echo "<td>" . $num . "</td>"; // Número
|
|
echo "<td>" . $datos[0] . "</td>"; // Nombre
|
|
echo "<td>" . $datos[1] . "</td>"; // Email
|
|
echo "<td>" . $datos[2] . "</td>"; // Ruta de Archivo
|
|
echo "</tr>";
|
|
}
|
|
|
|
// Cerrar el archivo
|
|
fclose($gestor);
|
|
|
|
// Cerrar la tabla HTML
|
|
echo "</table>";
|
|
} else {
|
|
echo "El archivo no existe.";
|
|
}
|
|
/*
|
|
// Con fgetcsv
|
|
|
|
echo '<table border="2">';
|
|
$archivo = fopen($nombre_archivo,'r');
|
|
while(($linea = fgetcsv($archivo, 0, ';'))) {
|
|
echo '<tr>';
|
|
echo '<td>' . $linea[0] . '</td>';
|
|
echo '<td>' . $linea[1] . '</td>';
|
|
echo '<td>' . $linea[2] . '</td>';
|
|
echo '</tr>';
|
|
}
|
|
echo '<table>';
|
|
fclose($archivo);
|
|
*/ |