PHPEye开源社区 » PHP技术讨论区 » 生成分页的静态页
《Programming PHP》第二版上市
2007-11-26 13:09 mayongzhan
生成分页的静态页

<!-- 写的差了点...直接一个func写下来...赶时间...其实也不错省事. -->
<!-- 整个文件最关键的就是生成,这部分也是最简单的...只对文件操作就可以了. -->
<?php
/**
* @name Htmlpage.php
* @date Sun Nov 25 23:55:09 CST 2007
* @copyright 马永占(MyZ)
* @author 马永占(MyZ)
* @link [url]http://blog.csdn.net/mayongzhan/[/url]
*/

class Htmlpage
{
       var $fileName="myz";//生成静态页面的文件名,默认为myz,不带.html
       var $fileDir;//生成静态页面存放的目录文件夹,末尾为/
       var $templateName="template";//调用模班页面名称,默认为template.html
       var $content;//新闻内容
       var $splitSymbol="马永占分页符";//内容分页符,默认为"马永占分页符"
       var $countPage;//总分页数
      
       public function createPages()
       {
              $contentArrayTemp = explode($this->splitSymbol, $this->content);
              $this->countPage = count($contentArrayTemp);
              //得到文件名
              $i = 0;
              while ($i < $this->countPage) {
                     if ($i<1) {
                            $filenameTemp[$i] = $this->fileDir . $this->fileName . ".html";
                     }
                     else {
                            $ii = $i + 1;
                            $filenameTemp[$i] = $this->fileDir . $this->fileName . "_{$ii}.html";
                     }
                     $i++;
              }
              
              if ($this->countPage != 1) {
                     //在每个有分页的页上加上页码
                     $i = 0;
                     while ($i <= $this->countPage) {
                            $ii = $i + 1;
                            //生成页码
                            $j = 0;
                            $showPages = "<br /><br /><br />";
                            while ($j < $this->countPage) {
                                   $jj = $j + 1;
                                   if ($i == $j) {
                                          $showPages .= "&nbsp;&nbsp;[{$jj}]";
                                   }
                                   else {
                                          $showPages .= "&nbsp;&nbsp;<a href='{$filenameTemp[$j]}'>[{$jj}]</a>";
                                   }
                                   $j++;
                            }
                            $contentArrayTemp[$i] .= $showPages;
                            $i++;
                     }
              }
              //写入文件
              $i = 0;
              while ($i < $this->countPage) {
                     $fp = fopen($filenameTemp[$i], 'wb');
                     $templatenameTemp = $this->templateName;
                     $fpT = fopen($templatenameTemp,'rb');
                     $str=fread($fpT,filesize($templatenameTemp));
                     $str=str_replace('<{$title}>',$this->fileName,$str);
                     $str=str_replace('<{$content}>',$contentArrayTemp[$i],$str);
                     fwrite($fp,$str);
                     fclose($fp);
                     fclose($fpT);
                     $i++;
              }
              return true;
       }/* end function createPages */
}/* end class Htmlpage */
?>
v

页: [1]
查看完整版本: 生成分页的静态页


Powered by Discuz! Archiver 5.5.0  © 2001-2006 Comsenz Inc.