Read text files and display them on the web page. This article provides two methods to read text files and display them on the php instance on the web page. The method is simple: Use fopen and add explode to implement.
Read text files and display them on webpages
This article provides two php tutorial examples for reading text files and displaying them on the web page. The method is simple: Use fopen, add explode, and.
*/
$ File = "./text.txt ";
$ Text = fread (fopen ($ file, "r"), filesize ($ file ));
$ Line = explode ("r", $ text );
Echo "<table width = 300 border = 1 cellspacing = 0 cellpadding = 0> ";
For ($ I = 0; $ I <= count ($ line); $ I ++ ){
$ Txt = explode ("t", $ line [$ I]);
Echo "<tr> <td> ". $ txt [0]. "</td> <td> ". $ txt [1]. "</td> <td> ". $ txt [2]. "</td> <td> ". $ txt [3]. "</td> </tr> ";
}
Echo "</table> ";
// Method 2
$ Content = file_get_contents('test.txt ');
$ Arr = explode ("n", $ content );
Echo "<table> ";
Foreach ($ arr as $ v ){
$ Tmp = explode ("", $ v );
Echo "<tr> ";
Echo "<td>". $ tmp [0]. "</td> ";
Echo "<td>". $ tmp [1]. "</td> ";
Echo "<td>". $ tmp [2]. "</td> ";
Echo "<td>". $ tmp [3]. "</td> ";
Echo "</tr> ";
Unset ($ tmp );
}
Echo "</table> ";
// Actually, there is no way to implement the instance, file function. I will not mention this too much. You can check it and read the content and save it to the data. You don't need to use the explode function.
/*
The text format is as follows:
Read the content of a text file as follows:
1 aaaa bbba ccca
2 aaaa bbbb cccb
3 aaaa bbbc cccc
3 aaaa bbbc cccc