Read a text file and display it in a Web page _php tutorial

Source: Internet
Author: User
Read the text file and display on the page in this article two kinds of reading text files and displayed in the PHP instance of the Web page, the method is very simple, with fopen, add explode,for to achieve.

Reads a text file and displays it in a Web page
This article is about two kinds of reading text files and displayed in the Web page PHP Tutorial instance, the method is very simple, with fopen, add explode,for on the implementation.
*/

$file = "./text.txt";
$text = Fread (fopen ($file, "R"), FileSize ($file));
$line = Explode ("R", $text);
echo "




"; for ($i = 0; $i <= count ($line), $i + +) {$txt = explode ("t", $line [$i]); echo " "; } echo "
". $txt [0]." ". $txt [1]." ". $txt [2]." ". $txt [3]."
";

Method Two

$content = file_get_contents (' test.txt ');

$arr = Explode ("n", $content);
echo "

foreach ($arr as $v) {
$tmp = Explode ("", $v);
echo "








echo "

"; "; Echo" "; Echo" "; Echo" "; Echo" "; Echo" "; unset ($tmp);}
" . $tmp [0]. "" . $tmp [1]. "" . $tmp [2]. "" . $tmp [3]. "
";

In fact, there is not a way to implement the above example, the file function Oh, this I do not say much. Check it out, it reads the content directly to the data, it is not necessary for us to use the explode function.
/*
The text text format is 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

http://www.bkjia.com/PHPjc/632048.html www.bkjia.com true http://www.bkjia.com/PHPjc/632048.html techarticle read the text file and display on the page in this article two kinds of reading text files and displayed in the PHP instance of the Web page, the method is very simple, with fopen, add explode,for to achieve. Read text ...

  • Related Article

    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.