PHP code example of alexskrypnyk / csvtable

1. Go to this page and download the library: Download alexskrypnyk/csvtable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

alexskrypnyk / csvtable example snippets


$csv = file_get_contents($csv_file);
// Render using the default renderer.
print (new CsvTable($csv))->render();

print (CsvTable::fromFile($file))->render();

print (CsvTable::fromFile($file))->render([CsvTable::class, 'renderTextTable']);

print (CsvTable::fromFile($file))->noHeader()->render([CsvTable::class, 'renderTextTable']);

print (CsvTable::fromFile($file))->render(Markdown::class);

print (CsvTable::fromFile($file))->render(function ($header, $rows, $options) {
  if (count($header) > 0) {
    $header = implode('|', $header);
    $header = $header . "\n" . str_repeat('-', strlen($header)) . "\n";
  }
  else {
    $header = '';
  }

  return $header . implode("\n", array_map(function ($row) {
    return implode('|', $row);
  }, $rows));
});