Home >Backend Development >PHP Tutorial >Read text files and display them on the web page_PHP tutorial

Read text files and display them on the web page_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:58:022312browse

Read text files and display them on the web page This article will talk about two PHP examples that read text files and display them on the web page. The method is very simple. Use fopen, add explode, and for to achieve it.

Read the text file and display it on the web page
This article will talk about two PHP tutorial examples of reading text files and displaying them on the web page. The method is very simple. Use fopen, add explode, and for to achieve it.
*/

$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 2

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

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

";

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

";
echo "";
echo "";
echo "";
echo "";
echo "";
unset($tmp);
}

echo "

" . $tmp[0] . "" . $tmp[1] . "" . $tmp[2] . "" . $tmp[3] . "
";

//In fact, there is no way to implement the above example, the file function, I won’t say too much about this. Just check it and you will find out. It reads the content and saves it directly to the data, so we 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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632048.htmlTechArticleReading text files and displaying them on the webpage This article talks about two ways to read text files and display them on the webpage in php Here is an example, the method is very simple, just use fopen, add explode, and for to achieve it. Read text...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn