字体:  

生成静态页html

9527 发表于: 2008-7-25 02:19 来源: PHPChina 开源社区门户

CODE:

<?php
session_start();
require('common.php');
require('lib/BluePage/BluePage.class.php');// 包含分页类

$count = $query->result($query->query("SELECT count(*) as count FROM gb_content"),'count');//总行数
$lines = 10; // 每页行数

$pBP = new BluePage($count, $lines) ;// 实例化分页类
$aPDatas = $pBP->get();//分页返回结果
$limit = $aPDatas['offset'] ;//起始行

$result = $query->query('SELECT * FROM gb_content order by id desc limit ' .$limit. ','.$lines);//查询数据
$gblist = array();
while ($row = $query->fetch_array($result)) {// 取一条数据
$row['username'] = htmlentities($row['username']);
$row['content'] = preg_replace('/(http[s]?:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"\s])*)/i','<a target="_blank" href="$1">$1</a>',htmlentities($row['content']));
$gblist[] = $row;
}
$query->free_result($result);
$query->close();
$strHtml = $pBP->getFull( $aPDatas);//html分页条
$smarty->assign('pagePanel',$strHtml);
$smarty->assign('gblist',$gblist);//给模板赋值
$fp = fopen('index.html','w');
fputs($fp,$smarty->fetch('index.tpl'));
fclose($fp);
$smarty->display('index.tpl');//显示模板内容
?>