这篇文章主要为大家详细介绍了php 文章内容分页或者生成静态化分页文件的简单示例,具有一定的参考价值,可以用来参考一下。
对php文章内容分页或者生成静态化分页文件感兴趣的小伙伴,下面一起跟随四海网的小编两巴掌来看看吧!
<?php /**
* @package myFramework create html class
* @Description Cut string
* @Environment : Apache2.0.59+PHP5.2.5+mysql5.0
* @arrange (512.笔记) www.q1010.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>';
}
}
/*** 来自四海网(www.q1010.com) ***/
本文来自:http://www.q1010.com/173/1132-0.html
注:关于php 文章内容分页或者生成静态化分页文件的简单示例的内容就先介绍到这里,更多相关文章的可以留意四海网的其他信息。
关键词:内容分页
四海网收集整理一些常用的php代码,JS代码,数据库mysql等技术文章。