informatica:programacion:php:snippets:ficheros
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
| informatica:programacion:php:snippets:ficheros [2021/06/30 15:46] – [CSV] tempwin | informatica:programacion:php:snippets:ficheros [2022/12/26 16:32] (actual) – tempwin | ||
|---|---|---|---|
| Línea 1: | Línea 1: | ||
| ====== PHP Snippets: Ficheros ====== | ====== PHP Snippets: Ficheros ====== | ||
| + | |||
| + | ===== Contar líneas ===== | ||
| + | |||
| + | Para contar las líneas de un fichero de texto: | ||
| + | |||
| + | <code php> | ||
| + | $file = new \SplFileObject(' | ||
| + | $file-> | ||
| + | |||
| + | echo $file-> | ||
| + | </ | ||
| ===== CSV ===== | ===== CSV ===== | ||
| Línea 14: | Línea 25: | ||
| $cabecera = [ | $cabecera = [ | ||
| - | columna1, | + | |
| - | columna2, | + | |
| - | columna3 | + | |
| ]; | ]; | ||
| Línea 45: | Línea 56: | ||
| <code php> | <code php> | ||
| $fichero = __DIR__ . DIRECTORY_SEPARATOR . " | $fichero = __DIR__ . DIRECTORY_SEPARATOR . " | ||
| - | $fp = fopen($fichero, | + | $fp = fopen($fichero, |
| while (($fila = fgetcsv($fp, | while (($fila = fgetcsv($fp, | ||
informatica/programacion/php/snippets/ficheros.1625060768.txt.gz · Última modificación: por tempwin
