php入门到放弃3新闻展示页面,从文件中读取内容,循环展示

php新闻展示页面,从文件中读取内容,循环展示。

代码实现

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title> news</title>
</head>
<body>
<center>
<table>

<tr>
<th>热度😊</th>
<th>标题</th>
<th>作者</th>
<th>发表时间</th>
<th>操作</th>
</tr>


<?php
$a = fopen('news.db','r');
for ($i =1; $i<=6; $i++){
if (feof($a)){
break;
}
$data = fgets($a);
$date_array = explode('||',$data);
$hot = $date_array[5];
$title = base64_decode($date_array[1]);
$author = $date_array[3];
$data = $date_array[4];
echo <<<EOF
<tr>
<td>{$hot}</td>
<td>{$title}</td>
<td>{$author}</td>
<td>{$data}</td>
<td>👍/👎</td>
</tr>
EOF;

}

?>

</table>
</body>
</center>
</html>