php - Create HTML table from multiple lines of strings -


i want take text file formatted so:

*note can change format of stored messages, there delimiters , different lines

;68.229.164.10:4/5/2013:hello  ;71.73.174.13:4/6/2013:oh hey 

(;ipaddress:timestamp:message)

and put in table looks so:

 ip                       time                  message  68.229.164.10            4/6/2013              hello  71.73.174.13             4/6/2013              oh hey 

i prefer use following:

http://php.net/manual/en/function.fgetcsv.php

and format output accordingly.

from example 1 on above referenced page:

<?php $row = 1; if (($handle = fopen("test.csv", "r")) !== false) {     while (($data = fgetcsv($handle, 1000, ",")) !== false) {         $num = count($data);         echo "<p> $num fields in line $row: <br /></p>\n";         $row++;         ($c=0; $c < $num; $c++) {             echo $data[$c] . "<br />\n";         }     }     fclose($handle); } ?> 

so, this...

<?php $row = 1; if (($handle = fopen("path_to_your_data_file", "r")) !== false) {      echo '<table>';     echo '<tr><td></td>ip<td>time</td><td>message</td></tr>';      while (($data = fgetcsv($handle, 1000, ":")) !== false) {         $num = count($data);         $row++;         if ($num > 2) {            echo '<tr>';            ($c=0; $c < $num; $c++) {               echo '<td>'.$data[$c].'</td>';            }            echo '</tr>';         }     }      echo '</table>';     fclose($handle); } ?> 

Comments