fork download
  1. <?php error_reporting(E_ALL&~E_NOTICE);
  2.  
  3. for(;$r=fgetcsv(STDIN);$a[]=$r) // read csv from STDIN, append to array $a
  4. foreach($r as$x=>$s)$e[$x]=max($e[$x],strlen($s)); // remember max length in array $e
  5. // print top border
  6. $t=["┬","┌","┐"];eval($L='foreach($e as$i=>$n)echo$t[!$i],str_repeat("─",$n);echo"$t[2]\n";');
  7. foreach($a as$k=>$r)
  8. {
  9. foreach($r as$i=>$s)echo"│",str_pad($s,$e[$i]);echo"│\n"; // print title/data row
  10. $t=["┼","├","┤"];if(!$k)eval($L); // print border below header
  11. }
  12. $t=["┴","└","┘"];eval($L); // print bottom border
  13.  
Success #stdin #stdout 0s 52512KB
stdin
Name,Age,Gender
Shaun,19,Male
Debra,19,Female
Alan,26,Male
George,15,Male
stdout
┌──────┬───┬──────┐
│Name  │Age│Gender│
├──────┼───┼──────┤
│Shaun │19 │Male  │
│Debra │19 │Female│
│Alan  │26 │Male  │
│George│15 │Male  │
└──────┴───┴──────┘