Revision [3852]

This is an old revision of ShowCsv made by NilsLindenberg on 2004-12-31 01:19:06.

 

Showing the content of a csv-file


if you save this as actions/showcsv.php, you have the usage:

{{showcvs file='uploads/file.cvs' delimeter=',')}}

file is the name of the file - needs to be on the same server as the wikka(?)
delimeter is the seperator for the entries

ToDo:
-document

<?php
/**
* Prints a table based on a csv-textfile.
*
* With this action a csv file, which has to be on the same server as the wikki, is read and its content presented in a table.
*
* @author mjwilco at yahoo dot com
* @author Nils Lindenberg (http://wikka.jsnx.com/NilsLindenberg)
*
* file string mandatory the name of the file which should be shown
*
* delimeter char optional the delimeter of the entries in the csv-file. standard is ","
*
*/


//get the params
$filename = $vars['file'];
if ($vars['delimeter']) $delimeter = $vars['delimeter'];
else $delimeter = ',';

if (file_exists($filename))
{
   $id = fopen($filename, "r");
   while ($data = fgetcsv($id, filesize($filename)))
   {
    $table[] = $data; //put each line into its own entry in the $table array
   }
   fclose($id);

   //print the table
   echo "<table border=1>\n";
   for($i=0;$i<count($table);$i++)
   {
    $entry = explode($delimeter, $table[$i][0]);
    echo "<tr>\n";
    for ($j=0; $j < count($entry); $j++)
    {
     echo "<td>";
     echo $entry[$j]."<br />";
     echo "</td>\n";
    }
    echo "</tr>\n";
   }
   echo "</table>\n";
}
else print("File not found.");
?>
There are 9 comments on this page. [Show comments]
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki