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 ""; ".$txt[0]." ".$txt[1]." ".$txt [2]." ".$txt[3]."
}
echo "
//Method 2
$content = file_get_contents('test.txt');
$arr = explode("n", $content);
echo "";
";foreach ($arr as $v) {
$tmp = explode(" ", $v);
echo ""; ";
echo "" . $tmp[0] . " ";
echo "" . $tmp[1] . " ";
echo "" . $tmp[2] . " ";
echo "" . $tmp[3] . " ";
echo "
unset($tmp);
}echo "
//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