该论坛的主题搜索是单独对themelist文件扫描来实现的,搜索的关键字可以是所有在主题列表中能够看到的信息,包括主题ID、主题、创建人、创建时间甚至帖子总数。
主题搜索的实现文件是search.php,其代码如下: <? echo "<body bgcolor='#FFFFCC'>";
echo "<h2><font color=blue>检索关键字:$keyword</font></h2>";
echo "<table width='100%' border='1'>"; echo "<tr bgcolor='#006600'>"; echo "<th width='10%'><div align='center'><font color='#FFFFFF'>序号</font></div></th>"; echo "<th width='45%'><div align='center'><font color='#FFFFFF'>主题</font></div></th>"; echo "<th width='15%'><div align='center'><font color='#FFFFFF'>创建人</font></div></th>"; echo "<th width='20%'><div align='center'><font color='#FFFFFF'>创建时间</font></div></th>"; echo "<th width='10%'><div align='center'><font color='#FFFFFF'>帖子数</font></div></th>"; echo "</tr>";
search($keyword, $themeid, $theme, $maker, $maketime, $notes); for($i = 0; $i < count($themeid); $i ++)
{ if($i % 2 == 0)
$bgcolor = '#CCFF99';
else
$bgcolor = '#A9FFA9';
echo "<tr bgcolor= $bgcolor>"; echo "<td width='10%'><div align='center'>$themeid[$i]</div></td>";
echo "<td width='45%'><div align='center'><a href = 'forum.php?action=read&id=$themeid[$i]&title=$theme[$i]¬es=$notes[$i]' title = '进入"$theme[$i]"主题'>$theme[$i]</a></div></td>";
echo "<td width='15%'><div align='center'>$maker[$i]</div></td>";
echo "<td width='20%'><div align='center'>$maketime[$i]</div></td>";
echo "<td width='15%'><div align='center'>$notes[$i]</div></td>";
echo "</tr>";
} echo "</table><br>";
echo "<div align=center><font color=red>共找到".$i."条记录 <a href='forum.php'>返回主题列表</a></font></div><br>";
echo "<font color=blue>检索说明:只要某主题在主题列表中的显示字段内有所需要的关键字,就会被搜索出来。<br>所以,搜索的时候可以输入所要找的主题题目的关键字、创建人名字、主题ID号、创建时间等进行搜索。</font>"; ?>
其中真正起作用的是search()函数,它是把符合要求的主题及其信息放入预定的五个数组中。在funcdef.php文件中search()定义如下:
<? //检索带有所要求关键字的记录,把相关数据列入5个数组
function search($keyword, &$themeid, &$theme, &$maker, &$maketime, &$notes) {
if($keyword == "") return;
if(!file_exists("rec/themelist"))
{
$fp = fopen("rec/themelist", "w+");
fwrite($fp, "0n0n");
fclose($fp);
}
$total_rec = file("rec/themelist");
$total_rec = array_slice($total_rec, 1, count($total_rec) - 2); $j = 0;
for($i = 0; $i < count($total_rec); $i ++)
{
if(eregi($keyword, $total_rec[$i]))
{
$themeid[$j] = strtok($total_rec[$i], "t");
$theme[$j] = strtok("t");
$maker[$j] = strtok("t");
$maketime[$j] = strtok("t");
$notes[$j] = strtok("t");
$j ++;
}
} } ?>
下次将介绍该论坛的帖子编辑/删除部分。(未完待续)
|
|