reenadak

delimited text file

Sep 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. /* $a = file_get_contents( "./directory.php_txt" );
  2.  
  3. $a = str_replace( array( "\n" , "^|" ) , array( "[NEW*LINE]" , "[tAbul*Ator]" ) , $a );
  4.  
  5. print "<table border=\"1\">";
  6. foreach( explode( "[NEW*LINE]" , $a ) AS $lines ) {
  7. print "<tr>";
  8. foreach( explode( "[tAbul*Ator]" , $lines ) AS $li ) {
  9. print "<td>";
  10. print $li ;
  11. print "</td>";
  12. }
  13.  
  14. print "</tr>";
  15. }
  16. print "</table>"; */
  17.  
  18. ?>
  19. <HTML>
  20. <HEAD>
  21. <TITLE> Example 6 </TITLE>
  22. </HEAD>
  23. <BODY><?
  24.  
  25. // the following statement opens the files called output.txt
  26. // and reads each line of the file into an array called $readfile
  27.  
  28. // Each line will be accessed by it's position in the array
  29. // $readfile[0] would be the first line because the array begins at 0
  30. // rather than 1
  31.  
  32. $readfile = file("./directory.php_txt");
  33.  
  34. // Create a loop that will read all elements of the array and print out
  35. // each field of the tab-delimited text file
  36.  
  37. for ($k=0; $k<=count($readfile)-1; $k++) {
  38. $fields = explode("^|",$readfile[$k]);
  39. echo "<br>".$fields[1];
  40. }
  41. ?>
  42.  
  43. </BODY>
  44. </HTML>
Add Comment
Please, Sign In to add comment