1 以文件名来保存发言和回复
// max.txt保存着最大的发言标题总数(不包括回复)
论坛分级文件...
第一个发言的文件名叫 1.txt
第一个发言的回复1 叫 1_1.txt
第一个发言的回复2 叫 1_2.txt
第一个发言的回复2的回复1叫 1_2_1.txt
第二个发言的文件名叫 2.txt
2 显示方法
//得到标题文章总数(不包括回复的文章)
$max = file("max.txt");
//分页显示
if($page == "")
{
$page = 1;
}
//每页显示的标题数目
$numperpage = 20;
//总标题数
$total = $max[0];
//总页数
$totalpage = round( ($total+$numperpage/2)/$numperpage );
//分级显示的函数
function show($filename)
{
//$id为论坛的分类名称
global $id;
//读入要显示的发言
$filenamemsg = file($filename);
//分割
$msg = split("\|\|bbs\|\|",$filenamemsg[0],99);
//显示当前的发言标题
print("
ilename=$filename&&id=$id','detail','menubar=0,toolbar=0,location=no,s
tatus=no,directories=0,scrollbars=yes,resizable=no,left=10,top=10,widt
h=550,height=400')\">".$msg[2]." ".$msg[0]." ".
$msg[4]."\r\n");
/查找是否有回复
for($i=1;$i{
//查找是否有 文件名_数字 的回复文件
$tmp = $filename."_".$i;
if( file_exists($tmp) )
{
//如果有,则调用递归显示这个回复以及回复的回复
print("
\r\n");
show($tmp);
print("
\r\n");
}
else
{
//否则中断循环
break;
}
}
//分级显示结束
print("");
}
//分页显示开始
$begin = $total-($page-1)*$numperpage;
//分页显示结束
$end = $begin - $numperpage;
//分级显示开始
print("
");
//循环显示标题以及各级回复
for($i=$begin;($i>0) && ($i>$end);$i--)
{
show("$i");
}
//分级显示结束
print("
");
3 发表新文章的方法
//处理最大发言数
$max = file("max.txt");
$maxnumber = $max[0]+1;
$handle = fopen("max.txt","w");
fputs($handle,$maxnumber);
fclose($handle);
//新建发言标题文件
$handle = fopen("$maxnumber","w");
//对发言进行预处理
$name = ereg_replace("$name = ereg_replace(">",">",$name);
if( strlen($name) > 20 )
{
$name = substr($name,0,20);
}
$email = ereg_replace("$email = ereg_replace(">",">",$email);
if( strlen($email) > 50 )
{
$email = substr($email,0,50);
}
$subject = ereg_replace("$subject = ereg_replace(">",">",$subject);
if( strlen($subject) > 100 )
{
$subject = substr($subject,0,100);
}
$body = ereg_replace("$body = ereg_replace(">",">",$body);
$body = ereg_replace("\r\n","
",$body);
if( strlen($body) > 5000 )
{
$body = substr($body,0,5000);
}
//保存发言
fputs($handle,"$name||bbs||$email||bbs||$subject||bbs||$body||bbs||".
date("Y年m月d日 H:i"));
fclose($handle);
4 回复的分级保存
//方法和发言基本相同,只是增加了一些判断
//请注意 $filename传递的是发言的文件名
// 可是是标题文件名 1.txt
// 也可能是回复文件名 13_3_2.txt 第13个发言标题的第3个回复的第3个回复
//查找已经有的最大回复
for($i=1;$i{
if(!file_exists($filename."_".$i))
{
break;
}
}
//找到,建立新的回复文件
//后面的与发言相同
fclose(fopen($filename."_".$i,"w"));
unlink("reply.tmp");
$handle = fopen($filename."_".$i,"w");
$name = ereg_replace("$name = ereg_replace(">",">",$name);
if( strlen($name) > 20 )
{
$name = substr($name,0,20);
}
$email = ereg_replace("$email = ereg_replace(">",">",$email);
if( strlen($email) > 50 )
{
$email = substr($email,0,50);
}
$subject = ereg_replace("$subject = ereg_replace(">",">",$subject);
if( strlen($subject) > 50 )
{
$subject = substr($subject,0,50);
}
$body = ereg_replace("$body = ereg_replace(">",">",$body);
$body = ereg_replace("\r\n","
",$body);
if( strlen($body) > 500 )
{
$body = substr($body,0,500);
}
fputs($handle,"$name||bbs||$email||bbs||$subject||bbs||$body||bbs||".
date("Y年m月d日 H:i"));
fclose($handle);
如果看不懂,到我的竹叶下载我的论坛源代码看看好了!!!
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn