Created
November 30, 2015 06:13
-
-
Save shouhei/d43a0960ac9e36a81fbd to your computer and use it in GitHub Desktop.
tsv形式のファイルを、HTMLのtableに出力する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| if($argc != 2){ | |
| echo "引数が足りません".PHP_EOL; | |
| exit; | |
| } | |
| $file = new SplFileObject($argv[1]); | |
| echo ' | |
| <!DOCYTP html> | |
| <head> | |
| <!-- Latest compiled and minified CSS --> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous"> | |
| <!-- Optional theme --> | |
| <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous"> | |
| <!-- Latest compiled and minified JavaScript --> | |
| <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script> | |
| </head> | |
| <body> | |
| <div class="container"> | |
| '.PHP_EOL; | |
| echo '<table class="table table-bordered">'.PHP_EOL; | |
| $row = $file->fgetcsv(' '); | |
| $table_row = array_map(function($n){ return '<td>'.$n.'</td>'; }, $row); | |
| $table_row_string = "<tr>".implode($table_row)."</tr>"; | |
| echo $table_row_string.PHP_EOL; | |
| while(!$file->eof()){ | |
| $row = $file->fgetcsv(' '); | |
| $table_row = array_map(function($n){ return '<td>'.$n.'</td>'; }, $row); | |
| $table_row_string = "<tr>".implode($table_row, '')."</tr>".PHP_EOL; | |
| echo $table_row_string.PHP_EOL; | |
| } | |
| echo "</table> | |
| </div> | |
| </body> | |
| </html>".PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment