php利用模板分页程序(带demo演示);(1/3)
//page.class.php
class page{
var $currentpage;
var $leftoffset;
var $rightoffset;
var $totalpage;//总页数
var $recordcount;//总记录数
var $pagesize;//每页显示条数
var $pageurl;
var $hypelink;
var $template;
var $tpl;
var $tagitems=array();
var $tagvalues=array();
var $sqlquery;
//构造函数
function page($currentpage=1,$pagesize=5,$leftoffset=2,$rightoffset=7,$pageurl="?page="){
echo "分页类开始";
$this->currentpage=ceil(abs(@$currentpage+0));
(empty($this->currentpage))?$this->currentpage=1:$this->currentpage=$this->currentpage;
$this->pagesize=ceil(abs(@$pagesize+0));
(empty($this->pagesize))?$this->pagesize=5:$this->pagesize=$this->pagesize;
$this->leftoffset=ceil(abs(@$leftoffset+0));
(empty($this->leftoffset))?$this->leftoffset=2:$this->leftoffset=$this->leftoffset;
$this->rightoffset=ceil(abs(@$rightoffset+0));
(empty($this->rightoffset))?$this->rightoffset=7:$this->rightoffset=$this->rightoffset;
$this->pageurl=$pageurl;
$this->setdefaulttagvalue();
}
//取得记录总数
//$sql="select count(id) as n from table";
function getrecordcount($sql,$conn){
$query=@mysql教程_query($sql,$conn);
if(!$query){echo "执行sql语句失败";exit();}
while($rs=mysql_fetch_row($query)){
$this->recordcount=$rs[0];//取得记录总数
}
$this->totalpage=ceil($this->recordcount / $this->pagesize);//计算总页数
if($this->currentpage > $this->totalpage){$this->currentpage=$this->totalpage;}//判断当前页是否大于总页数
mysql_free_result($query);
}
//select * from tb p->setlimit();
function setlimit(){
$limit="limit ".($this->currentpage-1)*$this->pagesize;
$limit.=",$this->pagesize";
return $limit;
}
function executesql($sql,$conn){
if(!$sql||!$conn){echo "参数传递错误";return false;}
$this->sqlquery=mysql_query($sql,$conn);
if(!$this->sqlquery){echo "执行sql语句失败";return false;}
}
function recordset(){
return mysql_fetch_array($this->sqlquery);
}
//取得模板内容
function gettemplate($filedir){
if(file_exists($filedir)){
$f=fopen($filedir,"r");
$this->template=fread($f,filesize($filedir));
}else{
echo "获取模板文件失败...文件不存在";
exit();
}
//取得区块内容
$start=strpos($this->template,"<!--templatebegin-->");
$end=strpos($this->template,"<!--templateend-->");
$this->tpl=substr($this->template,$start+strlen("<!--templatebegin-->"),$end-$start-strlen("<!--templateend-->")-2);
if($this->tpl==""){echo "模板内容为空,请检查标签设置是否正确。";exit();}
//echo $this->tpl;
}
本款生成静态页面程序实现原理是做好自定的模板标签,然后由str_replace把标签替换成指定的内容,再由fopen生成指定 文件名的静态页面,这样就OK了。
代码如下 | 复制代码 |
header('content-type:text/html;charset=utf-8'); if(!function_exists('file_get_contents')){ //如果系统没有file_get_contents()函数 function file_get_contents($file){ //自己写file_get_contents()函数 $fp = fopen($file,'r'); $content = fread($fp,filesize($file)); fclose($fp); return $content; } } $tmp_file = 'template.html'; //模板文件 $content = file_get_contents($tmp_file); //获得模板文件内容 $title = 'title'; //模板变量title要替换的值 $text = 'text'; //模板变量text要替换的值 $content = str_replace('<{title}>',$title,$content); //替换模板变量title $content = str_replace('<{text}>',$text,$content); //替换模板变量text //echo $content; //显示替换后的模板文件内容 makehtml('news.html',$content);//写入生成后的静态文件内容到news.html文件 echo '<a href="news.html" target="_blank">查看文件</a>'; function makehtml($file,$content){ $fp = fopen($file,'w'); fwrite($fp,$content); fclose($fp); } ?> |
//template.html
代码如下 | 复制代码 |
<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>makehtml</title> </head> <body> 这是模板变量title------<{title}> <br /> 这是模板变量text------<{text}> </body> </html> |
<?
//php教程生成pdf文件代码
/*
生成pdf文件如果真的生成很好,是很复杂的,下面我们来看看一款完整理的php生成pdf文件代码吧,他可以把文本文件生成pdf文件也可以利用图片文件生成pdf文件哦。
这款生成pdf文件用到文件有
fpdf.php
chinese.php
picpdf.php
*/
//fpdf.php代码
define('fpdf_version','1.6');
class fpdf
{
var $page; //current page number
var $n; //current object number
var $offsets; //array of object offsets
var $buffer; //buffer holding in-memory pdf
var $pages; //array containing pages
var $state; //current document state
var $compress; //compression flag
var $k; //scale factor (number of points in user unit)
var $deforientation; //default orientation
var $curorientation; //current orientation
var $pageformats; //available page formats
var $defpageformat; //default page format
var $curpageformat; //current page format
var $pagesizes; //array storing non-default page sizes
var $wpt,$hpt; //dimensions of current page in points
var $w,$h; //dimensions of current page in user unit
var $lmargin; //left margin
var $tmargin; //top margin
var $rmargin; //right margin
var $bmargin; //page break margin
var $cmargin; //cell margin
var $x,$y; //current position in user unit
var $lasth; //height of last printed cell
var $linewidth; //line width in user unit
var $corefonts; //array of standard font names
var $fonts; //array of used fonts
var $fontfiles; //array of font files
var $diffs; //array of encoding differences
var $fontfamily; //current font family
var $fontstyle; //current font style
var $underline; //underlining flag
var $currentfont; //current font info
var $fontsizept; //current font size in points
var $fontsize; //current font size in user unit
var $drawcolor; //commands for drawing color
var $fillcolor; //commands for filling color
var $textcolor; //commands for text color
var $colorflag; //indicates whether fill and text colors are different
var $ws; //word spacing
var $images; //array of used images
var $pagelinks; //array of links in pages
var $links; //array of internal links
var $autopagebreak; //automatic page breaking
var $pagebreaktrigger; //threshold used to trigger page breaks
var $inheader; //flag set when processing header
var $infooter; //flag set when processing footer
var $zoommode; //zoom display mode
var $layoutmode; //layout display mode
var $title; //title
var $subject; //subject
var $author; //author
var $keywords; //keywords
var $creator; //creator
var $aliasnbpages; //alias for total number of pages
var $pdfversion; //pdf version number
/*******************************************************************************
* *
* public methods *
* *
*******************************************************************************/
function fpdf($orientation='p', $unit='mm', $format='a4')
{
//some checks
$this->_dochecks();
//initialization of properties
$this->page=0;
$this->n=2;
$this->buffer='';
$this->pages=array();
$this->pagesizes=array();
$this->state=0;
$this->fonts=array();
$this->fontfiles=array();
$this->diffs=array();
$this->images=array();
$this->links=array();
$this->inheader=false;
$this->infooter=false;
$this->lasth=0;
$this->fontfamily='';
$this->fontstyle='';
$this->fontsizept=12;
$this->underline=false;
$this->drawcolor='0 g';
$this->fillcolor='0 g';
$this->textcolor='0 g';
$this->colorflag=false;
$this->ws=0;
//standard fonts
$this->corefonts=array('courier'=>'courier', 'courierb'=>'courier-bold', 'courieri'=>'courier-oblique', 'courierbi'=>'courier-boldoblique',
'helvetica'=>'helvetica', 'helveticab'=>'helvetica-bold', 'helveticai'=>'helvetica-oblique', 'helveticabi'=>'helvetica-boldoblique',
'times'=>'times-roman', 'timesb'=>'times-bold', 'timesi'=>'times-italic', 'timesbi'=>'times-bolditalic',
'symbol'=>'symbol', 'zapfdingbats'=>'zapfdingbats');
//scale factor
if($unit=='pt') php打包程序(在线解压与在线打包下载源码)
本程序支持文件下载解压与在线压缩,这样我们就查以实例在线解压与在线打包下载功能了。
php教程打包程序(在线解压与在线打包下载源码)
本程序支持文件下载解压与在线压缩,这样我们就查以实例在线解压与在线打包下载功能了。
*/
//phpzip.class.php
class phpzip{
var $datasec, $ctrl_dir = array();
var $eof_ctrl_dir = "x50x4bx05x06x00x00x00x00";
var $old_offset = 0; var $dirs = array(".");
function get_list($zip_name) {
$zip = @fopen($zip_name, 'rb');
if(!$zip) return(0);
$centd = $this->readcentraldir($zip,$zip_name);
@rewind($zip);
@fseek($zip, $centd['offset']);
for ($i=0; $i<$centd['entries']; $i++)
{
$header = $this->readcentralfileheaders($zip);
$header['index'] = $i;$info['filename'] = $header['filename'];
$info['stored_filename'] = $header['stored_filename'];
$info['size'] = $header['size'];$info['compressed_size']=$header['compressed_size'];
$info['crc'] = strtoupper(dechex( $header['crc'] ));
$info['mtime'] = $header['mtime']; $info['comment'] = $header['comment'];
$info['folder'] = ($header['external']==0x41ff0010||$header['external']==16)?1:0;
$info['index'] = $header['index'];$info['status'] = $header['status'];
$ret[]=$info; unset($header);
}
return $ret;
}
function add($files,$compact) {
if(!is_array($files[0])) $files=array($files);
for($i=0;$files[$i];$i++){
$fn = $files[$i];
if(!in_array(dirname($fn[0]),$this->dirs))
$this->add_dir(dirname($fn[0]));
if(basename($fn[0]))
$ret[basename($fn[0])]=$this->add_file($fn[1],$fn[0],$compact);
}
return $ret;
}
我们写了一个用php生成的日期日历生成类程序哦。非常的简单实例,希望文章对各位会有所帮助呀。
example:
include_once '/class/calendar.class.php';
$simple_example = new calendar();
print($simple_example->output_calendar());
*/
代码如下 | 复制代码 |
class calendar{ var $date; var $year; var $month; var $day; var $week_start_on = false; var $week_start = 7;// sunday var $link_days = true; var $link_to; var $formatted_link_to; var $mark_today = true; var $today_date_class = 'today'; var $mark_selected = true; var $selected_date_class = 'selected'; var $mark_passed = true; var $passed_date_class = 'passed'; var $highlighted_dates; var $default_highlighted_class = 'highlighted'; /* constructor */ function calendar($date = null, $year = null, $month = null){ $self = htmlspecialchars($_server['php_self']); $this->link_to = $self; if( is_null($year) || is_null($month) ){ if( !is_null($date) ){ //-------- strtotime the submitted date to ensure correct format $this->date = date("y-m-d", strtotime($date)); } else { //-------------------------- no date submitted, use today's date $this->date = date("y-m-d"); } $this->set_date_parts_from_date($this->date); } else { $this->year = $year; $this->month = str_pad($month, 2, '0', str_pad_left); } } function set_date_parts_from_date($date){ $this->year = date("y", strtotime($date)); $this->month = date("m", strtotime($date)); $this->day = date("d", strtotime($date)); } |
相关文章
- 我们这里介绍php与KindEditor编辑器使用时如何利用KindEditor编辑器的分页功能实现文章内容分页,KindEditor编辑器在我们点击分页时会插入代码,我们只要以它为分切符,就...2016-11-25
- 这篇文章主要介绍了C#开发Windows窗体应用程序的简单操作步骤,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2021-04-12
- 最近接了一个项目,其中有需求要用到jquery分页控件,上网也找到了需要分页控件,各种写法各种用法,都是很复杂,最终决定自己动手写一个jquery分页控件,全当是练练手了。写的不好,还请见谅,本分页控件在chrome测试过,其他的兼容性...2015-10-30
- 本文通过例子,讲述了C++调用C#的DLL程序的方法,作出了以下总结,下面就让我们一起来学习吧。...2020-06-25
- 本文通过两个示例讲解了一下Process类调用外部应用程序的基本用法,并简单讲解了StartInfo属性,有需要的朋友可以参考一下。...2020-06-25
- 这篇文章主要介绍了微信小程序 页面传值详解的相关资料,需要的朋友可以参考下...2017-03-13
- 本文实例讲述了jquery实现的伪分页效果代码。分享给大家供大家参考,具体如下:这里介绍的jquery伪分页效果,在火狐下表现完美,IE全系列下有些问题,引入了jQuery1.7.2插件,代码里有丰富的注释,相信对学习jQuery有不小的帮助,期...2015-10-30
- 大概有如下步骤 新建项目Bejs 新建文件package.json 新建文件Gruntfile.js 命令行执行grunt任务 一、新建项目Bejs源码放在src下,该目录有两个js文件,selector.js和ajax.js。编译后代码放在dest,这个grunt会...2014-06-07
- 这篇文章主要介绍了uniapp微信小程序:key失效的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-01-20
深入解析WordPress中加载模板的get_template_part函数
这篇文章主要介绍了WordPress中加载模板的get_template_part函数,其中重点讲解了其函数钩子的使用,需要的朋友可以参考下...2016-01-14将c#编写的程序打包成应用程序的实现步骤分享(安装,卸载) 图文
时常会写用c#一些程序,但如何将他们和photoshop一样的大型软件打成一个压缩包,以便于发布....2020-06-25- Vue.js通过简洁的API提供高效的数据绑定和灵活的组件系统.这篇文章主要介绍了vue.js 表格分页ajax 异步加载数据的相关资料,需要的朋友可以参考下...2016-10-20
- 本文实例讲述了PHP常用的小程序代码段。分享给大家供大家参考,具体如下:1.计算两个时间的相差几天$startdate=strtotime("2009-12-09");$enddate=strtotime("2009-12-05");上面的php时间日期函数strtotime已经把字符串...2015-11-24
- 这篇文章主要为大家详细介绍了微信小程序自定义tabbar组件,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下...2021-03-14
- 这篇文章主要介绍了微信小程序 网络请求(GET请求)详解的相关资料,需要的朋友可以参考下...2016-11-22
- mysql安装成功后有几个默认的配置模板,列表如下: my-huge.cnf : 用于高端产品服务器,包括1到2GB RAM,主要运行mysql my-innodb-heavy-4G.ini : 用于只有innodb的安装,最多有4GB RAM,支持大的查询和低流量 my-large.cnf : 用于...2015-03-15
- 这篇文章主要给大家介绍了关于微信小程序如何获取图片宽度与高度的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2021-03-10
- 这篇文章主要介绍了微信小程序 二维码生成工具 weapp-qrcode详解,教大家如何在项目中引入weapp-qrcode.js文件,通过实例代码给大家介绍的非常详细,需要的朋友可以参考下...2021-10-23
Springboot如何使用mybatis实现拦截SQL分页
这篇文章主要介绍了Springboot使用mybatis实现拦截SQL分页,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下...2020-06-19- 在php中要实现分页比起asp中要简单很多了,我们核心就是直接获取当前页面然后判断每页多少再到数据库中利用limit就可以实现分页查询了,下面我来详细介绍分页类实现程序...2016-11-25