代码如下 | 复制代码 |
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> |
代码如下 | 复制代码 |
<p id="errorremind"></p> <input id="unloadpic" type="button" value="上传图片" /> <ol id="uploadedname"></ol> |
代码如下 | 复制代码 |
<script type="text/网页特效" > |
upload.php文件
代码如下 | 复制代码 |
<?php $str = $hst;fwrite($fp,$str);fclose($fp); $file_path = 'm/'; |
//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;
}
php生成pdf文件代码 生成pdf文件如果真的生成很好,是很复杂的,下面我们来看看一款完整理的php生成pdf文件代码吧,他可以把文本文件生成pdf文件也可以利用图片文件生成pdf文件哦。
<?
//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;
}