PHP头条
热点:

读取文本文件并显示在网页


读取文本文件并显示在网页 本文章来讲二种读取文本文件并显示在网页的php实例了,方法很简单,用fopen,加explode,for就实现了。

读取文本文件并显示在网页
本文章来讲二种读取文本文件并显示在网页的php教程实例了,方法很简单,用fopen,加explode,for就实现了。
*/

$file = "./text.txt";
$text = fread(fopen($file,"r"),filesize($file));
$line = explode("r",$text);
echo "<table width=300 border=1 cellspacing=0 cellpadding=0>";
    for($i = 0; $i <= count($line); $i++){
 $txt = explode("t",$line[$i]);
 echo "<tr><td>".$txt[0]."</td><td>".$txt[1]."</td><td>".$txt[2]."</td><td>".$txt[3]."</td></tr>";
    }
echo "</table>";

//方法二

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

$arr = explode("n", $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>";

//其实不有一个方法来实现上的实例,file函数哦,这个我也不说多了。查查就知道了,它读出内容直接保存到数据,就不用我们使用explode函数了。
/*
文本文本格式如下

读取一个文本文件内容如下
1       aaaa    bbba    ccca
2       aaaa    bbbb    cccb
3       aaaa    bbbc    cccc
3       aaaa    bbbc    cccc

 

www.phpzy.comtrue/php/25714.htmlTechArticle读取文本文件并显示在网页 读取文本文件并显示在网页本文章来讲二种读取文本文件并显示在网页的php实例了,方法很简单,用fopen,加explode,for就实现了。 读取文本文件并显示在网页...

相关文章

    暂无相关文章

PHP之友评论

今天推荐