X-Git-Url: https://git.llucax.com/z.facultad/75.43/tp1.git/blobdiff_plain/9e86839e74733b8e67b56a5652aff670bf035ef2..ec14e221c612f4f8a710f17d1591416b16204eeb:/src/lib/file.php diff --git a/src/lib/file.php b/src/lib/file.php index 4b96769..812cfcc 100644 --- a/src/lib/file.php +++ b/src/lib/file.php @@ -30,6 +30,19 @@ if (!function_exists('fputcsv')) { } } +/** + * Agrega una entrada al final de un archivo csv. + * + * @return bool false si hay error. + */ +function fappendcsv($filename, $fields, $delim = ',') +{ + if (($f = fopen($filename, 'a')) === false) return false; // error + fputcsv($f, $fields, $delim); + fclose($f); + return true; +} + /** * Obtiene un archivo csv como array de arrays * @@ -39,7 +52,7 @@ function fgetallcsv($filename, $delim = ',') { if (($f = fopen($filename, 'r')) === false) return false; $data = array(); - while (!feof($f)) $data[] = fgetcsv($f, 4096, $delim); + while ($row = fgetcsv($f, 4096, $delim)) $data[] = $row; fclose($f); return $data; }