![图片.png](https://upload-images.jianshu.io/upload_images/12275941-f4490e7bdb6c188b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
图片.png
<?php
//读取记事本中学生信息的数据,并用表格展示
$filename="./student.txt";
//将文件内容读入到数组中
$arr=file($filename);
$str="<table style='border:1px solid gray' cellspacing=0>";
//循环输出数组每个元素(即文档中每一行的内容)
foreach($arr as $value){
$str.="<tr>";
//将获取的一行的字符串转为数组
$arrline=explode(',', $value);
//循环输出每一个元素的信息
foreach ($arrline as $val) {
$tb=iconv('gbk','utf-8',$val);
$str.="<td style='border:1px solid gray'>$tb</td>";
}
$str.="</tr>";
}
$str.="</table>";
echo $str;
![图片.png](https://upload-images.jianshu.io/upload_images/12275941-81ca27bf5b89444f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
图片.png