Posted By

Knarf on 11/18/09


Tagged

table array filegetcontents linenumbers


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

nerdfiles


Quickly load a file and give each line a linenumber.


 / Published in: PHP
 

A script I used for quickly load a file (see line 3) and then make a table which had linenumbers on each line. You may want to add a +1 when its generating the table...

  1. <?php
  2.  
  3. $file=file_get_contents("textfile.txt");
  4. $file_splited = preg_split("/\n/", $file);
  5.  
  6. $table = "<table>\n";
  7. foreach($file_splited as $itemname => $item) {
  8. $table .= "<tr> <td> " . $itemname . " </td> <td> " . $item . " </td> </tr>\n";
  9. }
  10. $table .= "</table>\n\n";
  11.  
  12. echo $table;
  13. ?>

Report this snippet  

You need to login to post a comment.