六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 1063|回复: 0

PHP新闻内容自动分页程序-it论坛-计算机论坛

[复制链接]
 楼主| 发表于 2014-1-8 15:00:36 | 显示全部楼层 |阅读模式
PHP新闻内容自动分页程序-it论坛-计算机论坛
  1. <?php
  2. /*==================================================================
  3. 程序说明:用于自动生成新闻静态页,手动添加分页功能,自动生成页码

  4. 程序作者:Www.Leadbbs.Com 简体中文版 QQ: 7275244

  5. 程序用途:演示用

  6. 时间:2005年9月30日

  7. 使用方法:绝对路径下建立info目录,建立Template.Html文件
  8. =================================================================*/
  9. if($Submit){
  10.      $FileName = "Test";
  11.      $NewsContent = "";
  12.      $NewsPage = "";
  13.      $ContentTemp = "";
  14.      $Content = htmlspecialchars($_POST['Content']);
  15.      if($Content==""){
  16.            echo "请输入内容";
  17.            exit;
  18.      }
  19.      $ContentTemp = explode("*分页符*", $Content);
  20.      $CountPage = count($ContentTemp);
  21.      //文件操作
  22.      for($k = 0 ; $k <= $CountPage-1 ; $k++){
  23.                        //判断页数,成生页码
  24.                              if ($CountPage > 1){      //不是单页新闻,需要显示分页信息
  25.                                    if ($k == 0){
  26.                                          $NowPage = 1;      //当前页
  27.                                          $NewsPage = GetPageCount($NowPage,$CountPage,$FileName);
  28.                                    }else{
  29.                                          $NowPage = $k + 1;
  30.                                          $NewsPage = GetPageCount($NowPage,$CountPage,$FileName);
  31.                                          $FileName = $FileName . "_" . $NowPage;
  32.                                    }
  33.                              }
  34.                        //生成页码结束
  35.                  $name="Template.html";
  36.                  $read=open($name);
  37.                  $read=str_replace("{Content}",$ContentTemp[$k],$read);
  38.                  $read=str_replace("{NewsPage}",$NewsPage,$read);
  39.                  write($read,"Info/" . $FileName . ".html");
  40.                  $FileName = "Test";
  41.      }
  42. }

  43. function open($name){
  44.          $f=@file($name);
  45.          if($f){
  46.                   foreach($f as $in){
  47.                         $read.=$in;
  48.                   }
  49.          }
  50.          return $read;
  51. }
  52. function write($s,$to){
  53.          $fp=@fopen($to,"w");
  54.          @fputs($fp,$s);
  55.          @fclose($to);
  56. }

  57. function GetPageCount($NowPage,$CountPage,$FileName){ //自动生成页码
  58. //==========显示结果============
  59. //上一页 1 2 3 下一页
  60. //上一页 ... 4 5 6 下一页
  61. //上一页 1 2 3 ... 下一页
  62. //上一页 ... 4 5 6 ... 下一页
  63. //==============================
  64. $ShowPageNum = 7;            //最好是单数,好看一些 ... 11 12 13 <14> 15 16 17 ...
  65. $PageUp = "";
  66. $PageDown = "";
  67. $GetPageCount = "";
  68.      if($NowPage == 1){
  69.            $GetPageCount = $GetPageCount . "<a href='" . $FileName . ".html'><font color='#ff0000'><b>1</b></font></a> ";
  70.      }else{
  71.            $GetPageCount = $GetPageCount . "<a href='" . $FileName . ".html'>1</a> ";
  72.      }
  73.      
  74.      if($CountPage <= $ShowPageNum){
  75.            for ($i = 2; $i <= $CountPage; $i++) {
  76.                  $GetPageCount = $GetPageCount . "<a href='" . $FileName . "_" . $i . ".html'>" . GetColor($i,$NowPage) . "</a> ";
  77.            }
  78.      }else{            //页数大于自定义的显示页码数量
  79.            if ((($NowPage - 3) > 1) && (($NowPage + 3) < $CountPage)){
  80.                  $GetPageCount = "... ";
  81.                  for ($i = $NowPage - 3; $i <= $NowPage + 3; $i++) {
  82.                        $GetPageCount = $GetPageCount . "<a href='" . $FileName . "_" . $i . ".html'>" . GetColor($i,$NowPage) . "</a> ";
  83.                  }
  84.                  $GetPageCount = $GetPageCount . "...";
  85.            }else{
  86.                  if ((($NowPage - 3) > 1) && (($NowPage + 3) >= $CountPage)){
  87.                        $GetPageCount = "... ";
  88.                        for ($i = $CountPage - $ShowPageNum+1; $i <= $CountPage; $i++) {
  89.                              $GetPageCount = $GetPageCount . "<a href='" . $FileName . "_" . $i . ".html'>" . GetColor($i,$NowPage) . "</a> ";
  90.                        }
  91.                  }else{
  92.                        for ($i = 2; $i <= $ShowPageNum; $i++) {
  93.                              $GetPageCount = $GetPageCount . "<a href='" . $FileName . "_" . $i . ".html'>" . GetColor($i,$NowPage) . "</a> ";
  94.                        }
  95.                        $GetPageCount = $GetPageCount . "...";
  96.                  }
  97.            }
  98.      }
  99.      //加首头页尾
  100.      if($NowPage > 1){
  101.            if($NowPage > 2){
  102.                  $PageUp = "<a href='" . $FileName . "_" . ($NowPage - 1) . ".html'>上页</a> ";
  103.            }else{
  104.                  $PageUp = "<a href='" . $FileName . ".html'>上页</a> ";
  105.            }
  106.      }
  107.      if ($NowPage < $CountPage){
  108.            $PageDown = "<a href='" . $FileName . "_" . ($NowPage + 1) . ".html'>下页</a> ";
  109.      }
  110.      $GetPageCount = "<a href='" . $FileName . ".html'>首页</a>  " . $PageUp . $GetPageCount . $PageDown . "<a href='" . $FileName . "_" . $CountPage . ".html'>末页</a>";
  111.      return $GetPageCount;
  112. }

  113. function GetColor($i,$NowPage){      //当前页标志色
  114.      if($i == $NowPage){
  115.            $GetColor = "<font color='#ff0000'><b>" . $NowPage . "</b></font>";
  116.      }else{
  117.            $GetColor = $i;
  118.      }
  119.      return $GetColor;
  120. }
  121. ?>
  122. <form name="form1" method="post" action="HtmlAutoPage.php">
  123.   <textarea name="Content" cols="100" rows="8"></textarea>
  124.   <input type="button" name="Submit" value="插入分页" onClick="form1.Content.value+='*分页符*';form1.Content.focus();">
  125.   <input type="submit" name="Submit" value="提交">
  126. </form>
复制代码
文章引用自:http://w.leadbbs.com/a/a.asp?B=2 ... c=nxt&rd=717594

该会员没有填写今日想说内容.
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表