php 文章内容分页或者生成静态化分页文件的解决办法
内容摘要
这篇文章主要为大家详细介绍了php 文章内容分页或者生成静态化分页文件的简单示例,具有一定的参考价值,可以用来参考一下。
对php文章内容分页或者生成静态化分页文件对此感
对php文章内容分页或者生成静态化分页文件对此感
文章正文
这篇文章主要为大家详细介绍了php 文章内容分页或者生成静态化分页文件的简单示例,具有一定的参考价值,可以用来参考一下。
对php文章内容分页或者生成静态化分页文件对此感兴趣的朋友,看看idc笔记做的技术笔记!
<?php /**
* @package myFramework create html class
* @Description Cut string
* @Environment : Apache2.0.59+PHP5.2.5+mysql5.0
* @arrange (www.idcnote.com)
* $test = <<<EOF
* EOF;
*
* $html = new myFrame_HTML(100);
* $html->createHtml($html->cut($test, 1), '11');
*
*/
class myFrame_HTML extends myFrame
{
//定义每页显示的数量
var $count = 5000;
var $pageAmount;
var $charSet = 'UTF-8';
var $folder = 'html/';
function __construct($count ='')
{
if($count != '')
{
$this->count = $count;
}
}
/**
* cut string for pages
*
* @param string $contents
* @param int $page this is start page
* @return array
*/
function cut($contents, $page = 1)
{
$total = mb_strlen($contents);
if($total < $this->count)
{
$this->pageAmount['contents'][] = $contents;
$this->pageAmount['page'][] = $page;
}else{
$this->pageAmount['contents'][] = mb_strcut($contents, 0, $this->count, $this->charSet);
$this->pageAmount['page'][] = $page;
$almost = mb_strcut($contents, $this->count, $total, $this->charSet);
$this->cut($almost, $page+1);
}
return $this->pageAmount;
}
function createDynamic($array, $page, $pageName = 'page', $queryString = '')
{
$pageFoot = $array['page'];
$contents = $array['contents'];
$html = '';
$count = sizeof($contents);
for ($i = 0; $i < $count; $i++)
{
$thisFile = $fileName;
if($count == 1)
{
$html[$pageFoot[$i]]= $contents[$i];
}else{
$html[$pageFoot[$i]]= $contents[$i] . $this->createDynamicFoot($pageFoot, $pageFoot[$i] ,$pageName, $queryString);
}
}
return $html[$page];
}
function createDynamicFoot($page, $current, $pageName, $queryString)
{
foreach ($page as $p)
{
if($p == $current)
{
$foot .= ' [ '. $p .' ]';
}else{
$foot .= ' [ <a href="?'. $queryString . '&' . $pageName .'=' . $p .'">'.$p.'</a> ]';
}
}
return '<div class="pageFoot">' . $foot . '</div>';
}
/**
* create html
*
* @param array $array
* @param string $fileName
*/
function createHtml($array, $fileName)
{
$pageFoot = $array['page'];
$contents = $array['contents'];
$html = '';
$count = sizeof($contents);
for ($i = 0; $i < $count; $i++)
{
$thisFile = $fileName;
if($count == 1)
{
$html= $contents[$i];
$thisFile = $fileName . '.html';
}else{
$html= $contents[$i] . $this->createFoot($pageFoot, $pageFoot[$i], $fileName);
if($pageFoot[$i] == 1)
{
$thisFile = $thisFile . '.html';
}else{
$thisFile = $thisFile . '_' . $pageFoot[$i] . '.html';
}
}
file_put_contents($this->folder . $thisFile, $html);
}
}
/**
* create page index
*
* @param int $page
* @param int $current
* @param string $fileName
* @return string
*/
function createFoot($page, $current, $fileName)
{
$foot = '';
foreach ($page as $p)
{
if($p == $current)
{
$foot .= ' [ '. $p .' ]';
}else{
if($p == 1)
{
$foot .= ' [ <a href="'. $fileName . '.html">'.$p.'</a> ]';
}else{
$foot .= ' [ <a href="'. $fileName. '_' .$p . '.html">'.$p.'</a> ]';
}
}
}
return '<div class="pageFoot">' . $foot . '</div>';
}
}
/*** 来自php教程(www.idcnote.com) ***/
注:关于php 文章内容分页或者生成静态化分页文件的简单示例的内容就先介绍到这里,更多相关文章的可以留意
代码注释