File modules/cms/generator/filter/Csv2HtmlFilter.class.php
Last commit: Fri Sep 18 23:04:13 2020 +0200 Jan Dankert Refactoring: Renaming module "cms/publish" to "cms/generator"
1 <?php 2 3 4 namespace cms\generator\filter; 5 6 7 class Csv2HtmlFilter extends AbstractFilter 8 { 9 public $withHeader = false; 10 public $delimiter = ';'; 11 public $enclosure = '"'; 12 13 public function filter( $value ) 14 { 15 $outputRow = function( $line, $cellTag) { 16 return "<tr><$cellTag>".implode("</$cellTag><$cellTag>",str_getcsv( $line,$this->delimiter,$this->enclosure ))."</$cellTag></tr>"; 17 18 }; 19 20 $lines = explode("\n",$value ); 21 22 $out = ''; 23 $out .= '<table>'; 24 25 if ( $this->withHeader && $lines ) 26 { 27 $out .= '<thead>'; 28 $out .= $outputRow( array_shift($lines),'th'); 29 $out .= '</thead>'; 30 } 31 32 33 $out .= '<tbody>'; 34 foreach( $lines as $line ) 35 $out .= $outputRow( $line,'td'); 36 $out .= '</tbody>'; 37 38 $out .= '</table>'; 39 40 return $out; 41 } 42 }
Downloadmodules/cms/generator/filter/Csv2HtmlFilter.class.php
History Fri, 18 Sep 2020 23:04:13 +0200 Jan Dankert Refactoring: Renaming module "cms/publish" to "cms/generator"