Read a text file and display it on a Web page

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.