=====Handle csv-data===== This library is intended to hold functions which handle data from (and perhaps in some time) to *.csv files. < is stripped off. * * Based on a given type of separator, every line is exploded and every entry of the line * put into the second dimension of the array, leading to the following structure: * array[line][entry] * * @package Library * @subpackage HandleCsvData * * @author {@link http://it.php.net/manual/en/function.fgetcsv.php mjwilco at yahoo dot com} (basic code) * @author {@link http://wikka.jsnx.com/NilsLindenberg Nils Lindenberg} (error-handling and stripping html) * * @param ? $file mandatory: name and path of the csv-file * @param char $separator optional: the separator used for dividing the entries * standard: "," * * @return either a two-dimensional array containing the data of the file, or, in case of an error, FALSE * * @todo - excel seem to make different *.csv files? * - error-handling for $rows = Striphtml * - detecting if $separator is only one char */ function GetCsvData($file, $separator=",") { $endingtest = explode(".", $file); if ($endingtest[count($endingtest)-1] != "csv") //checks if the ending of the file is *.csv { echo 'This file does not seem to be an csv-file. Please check the extension of it ('.$file.')'; # i18n return FALSE; } if (file_exists($file)) { $id = fopen($file, "r"); if(!$id) { echo 'The file you specified could not be opend. Please check the reading permission for the file ('.$file.')'; # i18n return FALSE; } while ($data = fgetcsv($id, filesize($file), $separator)) //put each line into its own entry in the $rows array { $rows[] = StripHtml($data); } fclose($id); return($rows); } echo 'The file you specified was not found. Please check you input ('.$file.')'; # i18n return FALSE; } function StripHtml($data) { if (is_array($data)) { for ($i=0;$i\n"; //first entry handeld seperate, possible header echo "\n"; for ($j = 0; $j < count($data[0]); $j++) { if ($header == 'on') echo ""; else echo ""; echo $data[0][$j]; if ($header == 'on') echo "\n"; //50 else echo "\n"; } echo "\n"; for($i=1;$i'; for ($j=0; $j < count($data[$i]); $j++) { echo ''; echo $data[$i][$j]; echo "\n"; } echo "\n"; } echo "\n"; } else echo 'The table could not be drawn because the data given to PrintCsvTable was no array.'; # i18n } /** * Transforms a one-dimensional array into a two-dimensional. * * The given one-dimensional array is changed into a two-dimensional array * with n=$itemsperline items in the second dimension. * * @package Library * @subpackage HandleCsvData * * @author {@link http://wikka.jsnx.com/NilsLindenberg Nils Lindenberg} * * @param array $onedimension mandatory: the array which will be transformed * @param int $itemsperline mandatory: number of entries in the second dimension * * @return either a two-dimensional array, or, in case of an error, FALSE * * @todo - errorhandling * */ function ArrayOneDimensionToTwo($onedimension,$itemsperline) { $i=0; $j=0; $k=0; for ($i=0;$i %% ---- CategoryUserContributions