Quickly load a file and give each line a linenumber.


/ Published in: PHP
Save to your folder(s)

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...


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.