Revision [23650]

This is an old revision of PLG-Csv made by BrianKoontz on 2019-09-02 20:27:50.

 

CSV 2 Table formatter

test
See Also
NOT Included in any Wikka version yet
Last edited by BrianKoontz
Mon, 02 Sep 2019 20:27 UTC [diff]

What

Example
%%(csv)
;***a***;"***b***";***c***
***1***;d;"e";f
#test

***2***;g;;h
***3***;I;J;"K"
%%
 abc
1def
2g h
3IJK


Features
To not disturb the alternated layout: add 2 (comment)lines...

To Do

Installation

Code
<?php
// convert inline csv data into a table.
// by OnegWR, may 2005, license GPL
$csv_printheader=0;
foreach(split("\n", $text) as $csv_n => $csv_line){
        if(preg_match("/^#|^\s*$/",$csv_line)) continue;
        if( $csv_printheader == 0){ print "<table cellpadding=\"5\" cellspacing=\"1\"><tbody>\n"; $csv_printheader=1; }
        print ($csv_n%2) ? "<tr bgcolor=\"#ffffee\">" : "<tr bgcolor=\"#eeeeee\">";
        foreach(split(";", $csv_line) as $csv_nn => $csv_cell){
                if(preg_match("/^\s*$/",$csv_cell)){
                        print "<td>&nbsp;</td>";
                }elseif(preg_match("/^(\"?)\*\*\*(.*?)\*\*\*(\"?)$/",$csv_cell,$matches)){
                        print "<td bgcolor=\"#cccccc\">".
                                $this->htmlspecialchars_ent($matches[2])."</td>";
                }elseif(preg_match("/^(\"?)(.*?)(\"?)$/",$csv_cell,$matches)){
                        print "<td>".$this->htmlspecialchars_ent($matches[2])."</td>";
                }else{
                        print "<td>".$this->htmlspecialchars_ent($csv_cell)."</td>";
                }
        }
        print "</tr>\n";
}
if( $csv_printheader == 1) print "</tbody></table>\n";
?>

History

Bugs


CategoryUserContributions
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki