我有一個小文本顯示來自文本文件的博客帖子,如何添加分頁以便一次只顯示5篇博文?帶有PHP的分頁文本文件
下面是腳本:
<html>
<head>
<title>blog</title>
</head>
<body>
<?php
$mode = 0;
if ($mode == 0) { $opFile = "blogfile.txt"; }
$fp = fopen($opFile,"r") or die("Error Reading File");
$data = fread($fp, filesize($opFile));
fclose($fp);
$line = explode("\n", $data);
$i=count($line);
for ($n=0 ; $n < $i-1 ; $n++) {
$blog = explode("|", $line[$n]);
if (isset($blog[0]))
{
echo "<div class=\"blog-post\">";
echo "<p class=\"blog-title\">".$blog[1]."</p>";
echo "<p class=\"blog-message\">".$blog[2]."</p>";
echo "<p class=\"blog-date\">Posted: " .$blog[0]."</p>";
echo "<div style=\"clear: both;\"></div>";
echo "</div>";
}
}
?>
</body>
</html>
這裏是文本文件:
Feb 17 2010|Title|Blog post content here|[end]
Feb 17 2010|Title|Blog post content here|[end]
Feb 17 2010|Title|Blog post content here|[end]
Feb 17 2010|Title|Blog post content here|[end]
任何幫助,不勝感激!
你爲什麼從文本文件而不是數據庫讀取? – 2010-02-17 21:27:42
因爲它是不使用任何數據庫的較大腳本的一部分,這是它的一個「特性」。只需將它放在服務器上即可。我知道DB的更好,但這是我需要這個工作。 – mark 2010-02-17 21:38:24