| The code is as follows |
Copy Code |
$file = "./text.txt"; $text = Fread (fopen ($file, "R"), FileSize ($file)); $line = Explode ("", $text); echo "<table width=300 border=1 cellspacing=0 cellpadding=0>"; for ($i = 0; $i <= count ($line); $i + +) { $txt = Explode ("", $line [$i]); echo "<tr><td>". $txt [0]. " </td><td> ". $txt [1]." </td><td> ". $txt [2]." </td><td> ". $txt [3]." </td></tr> "; } echo "</table>"; |
Method Two
| code is as follows |
copy code |
| $content = file_get_contents (' test.txt '); $arr = Explode ("", $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>; |
In fact, there is not a way to implement the instance on, the file function Oh, I don't say much about that. Check it out, it read the content directly saved to the data, we do not use the explode function.
/*
Text text is formatted as follows
Read the contents of a text file as follows
1 AAAA bbba Ccca
2 AAAA bbbb CCCB
3 AAAA bbbc CCCC
3 AAAA bbbc CCCC