文本文件实现文章管理代码(1)

require "config.php";
$fp=fopen ("./file/title.dat","r");
$filefread ($fpfilesize("./file/title.dat"));
$xindexexplode ($big,$file);
$sum count($xindex);
$sum $sum-1;
### 分页 ###
if (!isset($page)) $page=1;
$totalpage=ceil($sum/$pagesize);
if (
$totalpage==0) {
    
$totalpage=1;
    
$page=1;
}
$start=$pagesize*($page-1)+1;
$end=$pagesize+$start;
?>
<html>
<head>
<title>文章管理代码片断(演示)</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="css/index.css">
<script language="javascript">
function openwin(filename)
{        window.open("read.php?id="+filename,"","height=500,width=600,resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
    }
</script>
</head>

<body bgcolor="#ffffff">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td width="1%"><img src="image/conner1.gif" width="20" height="20"></td>
    <td width="29%" bgcolor="#FFCC66">文本文件文章系统 Demo</td>
    <td colspan="2" bgcolor="#FFCC66"> 
      <div align="right"> 找到 <b><?php echo $sum;?></b> 篇</div>
    </td>
    <td width="14%" bgcolor="#FFCC66"> 
      <div align="right"><img src="image/conner3.gif" width="20" height="20"></div>
    </td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr valign="top"> 
    <td width="78%" align="right"> 
      <table width="95%" border="0" cellspacing="0" cellpadding="0">
        <tr valign="top"> 
          <td> <br>
<?php
if ($sum!=0) {

    for (
$start;$start<=$end;$start++) {
        
$contexplode($small,$xindex[$start]);
            echo 
"★<a href="javascript:openwin('$cont[2]')">$cont[0]</a> ($cont[1])<br>";
            if (
$start==$sum) break;
    }
}
else {
    echo 
"没有文章";
}
?>
            <br><div align="right"> 共<b><?php echo $totalpage;?></b>页 第<b><?php echo $page;?></b>页 ·<?php
if ($page!=1){
     
$back=$page-1;
        echo
"<a href="$php_self?page=1">首页</a> <a href="$php_self?page=$back">上一页</a>";
}
if (
$page==1){
       echo
"首页 上一页";
}
if(
$page!=$totalpage){
    
$next=$page+1;
        echo
" <a href="$php_self?page=$next">下一页</a> <a href="$php_self?page=$totalpage">尾页</a>";
}
if(
$page==$totalpage){
        echo
" 下一页 尾页";
}
?>·</div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="3%"><img src="image/conner2.gif" width="20" height="20"></td>
    <td width="94%" bgcolor="#FFCC66">
      <div align="center">制作:晓风残月(电脑疯子) <a href="http://safebase.yeah.net" target="_blank">http://safebase.yeah.net</a></div>
    </td>
    <td width="3%" bgcolor="#FFCC66"> 
      <div align="right"><img src="image/conner4.gif" width="30" height="20"></div>
    </td>
  </tr>
</table>
</body>
</html>
<?php
$fp
=fopen("counter.txt","r");
$counter=fgets($fp,8);
fclose($fp);
$counter+=1;
$fp=fopen("counter.txt","w");
fputs($fp,$counter);
fclose($fp);
echo 
"$counter views since 2000/10/07";
?>

// end of index.php
// read.php
<?php
##############################################
#      文本文章发布系统代码片断
#          作者:晓风残月([email protected])
#          主页: http://safebase.yeah.net
##############################################
require "config.php";
$fp=fopen ("./file/title.dat","r");
$filefread ($fpfilesize("./file/title.dat"));
$xindexexplode ($big,$file);
$sum count($xindex);
$sum $sum-1;
### 分页 ###
if (!isset($page)) $page=1;
$totalpage=ceil($sum/$pagesize);
if (
$totalpage==0) {
    
$totalpage=1;
    
$page=1;
}
$start=$pagesize*($page-1)+1;
$end=$pagesize+$start;
?>
<html>
<head>
<title>文章管理代码片断(演示)</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="stylesheet" type="text/css" href="css/index.css">
<script language="javascript">
function openwin(filename)
{        window.open("read.php?id="+filename,"","height=500,width=600,resizable=no,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no");
    }
</script>
</head>

<body bgcolor="#ffffff">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr> 
    <td width="1%"><img src="image/conner1.gif" width="20" height="20"></td>
    <td width="29%" bgcolor="#FFCC66">文本文件文章系统 Demo</td>
    <td colspan="2" bgcolor="#FFCC66"> 
      <div align="right"> 找到 <b><?php echo $sum;?></b> 篇</div>
    </td>
    <td width="14%" bgcolor="#FFCC66"> 
      <div align="right"><img src="image/conner3.gif" width="20" height="20"></div>
    </td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr valign="top"> 
    <td width="78%" align="right"> 
      <table width="95%" border="0" cellspacing="0" cellpadding="0">
        <tr valign="top"> 
          <td> <br>
<?php
if ($sum!=0) {

    for (
$start;$start<=$end;$start++) {
        
$contexplode($small,$xindex[$start]);
            echo 
"★<a href="javascript:openwin('$cont[2]')">$cont[0]</a> ($cont[1])<br>";
            if (
$start==$sum) break;
    }
}
else {
    echo 
"没有文章";
}
?>
            <br><div align="right"> 共<b><?php echo $totalpage;?></b>页 第<b><?php echo $page;?></b>页 ·<?php
if ($page!=1){
     
$back=$page-1;
        echo
"<a href="$php_self?page=1">首页</a> <a href="$php_self?page=$back">上一页</a>";
}
if (
$page==1){
       echo
"首页 上一页";
}
if(
$page!=$totalpage){
    
$next=$page+1;
        echo
" <a href="$php_self?page=$next">下一页</a> <a href="$php_self?page=$totalpage">尾页</a>";
}
if(
$page==$totalpage){
        echo
" 下一页 尾页";
}
?>·</div>
          </td>
        </tr>
      </table>
    </td>
  </tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="3%"><img src="image/conner2.gif" width="20" height="20"></td>
    <td width="94%" bgcolor="#FFCC66">
      <div align="center">制作:晓风残月(电脑疯子) <a href="http://safebase.yeah.net" target="_blank">http://safebase.yeah.net</a></div>
    </td>
    <td width="3%" bgcolor="#FFCC66"> 
      <div align="right"><img src="image/conner4.gif" width="30" height="20"></div>
    </td>
  </tr>
</table>
</body>
</html>
<?php
$fp
=fopen("counter.txt","r");
$counter=fgets($fp,8);
fclose($fp);
$counter+=1;
$fp=fopen("counter.txt","w");
fputs($fp,$counter);
fclose($fp);
echo 
"$counter views since 2000/10/07";
?>