我写了一个简单的不能再简单的类.相信你会看懂的.<?php class test { function aaa($a="aaa"){ echo $a; } function bbb($b="bbb"){ echo $b; } function ccc($c="ccc"){ echo $c; } }$test = new test;$test->aaa(); $test->bbb(); $test->ccc(); ?>显示结果为 aaabbbccc就这么简单.依我理解.类就是一个函数的聚合罢了.比较适合像我这种比较懒的人..嘿嘿
<?php/* ¶àÓïÑÔÖ§³Ö PDF ÎļþÉè¼ÆÆ÷ */ class PMultLanguagePDF extends PCpdf { //¹¹Ô캯Êý³õʼ»¯±äÁ¿ var $ReportID,$RptTitle,$AuditDate,$RptType,$Width,$Height,$TitleFontName,$NormalFontName,$TitleSize,$NormalSize,$HotelName; //¶¨Ò屨±íÓïÑԺͻù±¾×ÖÌå,ÊÇ·ñÏÔʾ´ËÓïÑÔ var $language,$BaseFontName,$showLanguage; //¶¨Òå²Ù×÷¾ä±ú var $pdfRpt; //¶¨Òå´òÓ¡Ò³ÃæËı߾à var $outTop,$outBottom,$outLeft,$outRight; //ÎļþµÄȫ·¾­ var $filepath; //¶¨ÒåÊý¾Ý¼¯ÐÐÊý¡¢ÁÐÊý,Ò³×ÜÊý,µ±Ç°Ò³Âë,ÿҳ×î¶à¿ÉÒÔÏÔʾµÄ¼Ç¼Êý,µ±Ç°ÒÔÏÔʾµ½µÄ¼Ç¼Êý,±¨±íÍ·µÄ¸ß¶È,±¨±íÍ·µÄÐÐÊý var $dataRowsCounts,$dataColsCounts,$PageCounts,$CurrPageNum,$PageOfRowsCounts,$CurrRecNums,$HeaderHeight,$headerCounts;
//Ðмä¾à var $RowsHeight = 13; //×ֶεıêÌâÃû³Æ£¬¿í¶È£¬Êý¾Ý. var $FieldName,$FieldWidth,$FieldData; //This is construct function. /* $rpttype : horizontal , vertical */ function PMultLanguagePDF($reportid,$rpttitle,$auditdate,$rpttype,$hotelname,$width="595",$height="842"){ $rpttype = strtoupper($rpttype);
http://www.cngnu.org/technology/0584/207.html
class test
{
function aaa($a="aaa"){
echo $a;
} function bbb($b="bbb"){
echo $b;
} function ccc($c="ccc"){
echo $c;
}
}$test = new test;$test->aaa();
$test->bbb();
$test->ccc();
?>显示结果为
aaabbbccc就这么简单.依我理解.类就是一个函数的聚合罢了.比较适合像我这种比较懒的人..嘿嘿
¶àÓïÑÔÖ§³Ö PDF ÎļþÉè¼ÆÆ÷
*/
class PMultLanguagePDF extends PCpdf { //¹¹Ô캯Êý³õʼ»¯±äÁ¿
var $ReportID,$RptTitle,$AuditDate,$RptType,$Width,$Height,$TitleFontName,$NormalFontName,$TitleSize,$NormalSize,$HotelName; //¶¨Ò屨±íÓïÑԺͻù±¾×ÖÌå,ÊÇ·ñÏÔʾ´ËÓïÑÔ
var $language,$BaseFontName,$showLanguage; //¶¨Òå²Ù×÷¾ä±ú
var $pdfRpt; //¶¨Òå´òÓ¡Ò³ÃæËı߾à
var $outTop,$outBottom,$outLeft,$outRight; //ÎļþµÄȫ·¾­
var $filepath; //¶¨ÒåÊý¾Ý¼¯ÐÐÊý¡¢ÁÐÊý,Ò³×ÜÊý,µ±Ç°Ò³Âë,ÿҳ×î¶à¿ÉÒÔÏÔʾµÄ¼Ç¼Êý,µ±Ç°ÒÔÏÔʾµ½µÄ¼Ç¼Êý,±¨±íÍ·µÄ¸ß¶È,±¨±íÍ·µÄÐÐÊý
var $dataRowsCounts,$dataColsCounts,$PageCounts,$CurrPageNum,$PageOfRowsCounts,$CurrRecNums,$HeaderHeight,$headerCounts;
//Ðмä¾à
var $RowsHeight = 13; //×ֶεıêÌâÃû³Æ£¬¿í¶È£¬Êý¾Ý.
var $FieldName,$FieldWidth,$FieldData; //This is construct function.
/*
$rpttype : horizontal , vertical
*/
function PMultLanguagePDF($reportid,$rpttitle,$auditdate,$rpttype,$hotelname,$width="595",$height="842"){ $rpttype = strtoupper($rpttype);
$this->ReportID = $reportid;
$this->RptTitle = $rpttitle;
$this->AuditDate = $auditdate;
$this->RptType = $rpttype;
$this->HotelName = $hotelname;
//ÅжÏÊÇÊú´òÓ¡»¹ÊǺá´òÓ¡
if ($rpttype == "VERTICAL"){
$this->Width = $width;
$this->Height = $height;
}else if ($rpttype == "HORIZONTAL"){
$this->Width = $height;
$this->Height = $width;
} }//End PSimplePDFDesigner($reportid).
//ÉèÖôòÓ¡Ò³ÃæËı߾à
function setOutPage($top,$bottom,$left,$right){
$this->outTop = $top;
$this->outBottom = $bottom;
$this->outLeft = $left;
$this->outRight = $right;
} //±¨±í³õʼ»¯
function init(){
$this->dataRowsCounts = count($this->FieldData);
$this->dataColsCounts = count($this->FieldData[0]);
$this->headerCounts = count($this->FieldName);
if ($this->headerCounts == 1){
$this->HeaderHeight = 103;
}else{
$this->HeaderHeight = 88 + $this->RowsHeight * $this->headerCounts;
} $this->PageOfRowsCounts = floor(($this->Height - $this->outTop - $this->outBottom - $this->HeaderHeight) / $this->RowsHeight);
$this->PageCounts = ceil($this->dataRowsCounts / $this->PageOfRowsCounts);
$this->CurrPageNum = 1;
$this->CurrRecNums = 0; //¹ØÓÚ×ÖÌåÖÖÀ༰´óС
$this->TitleFontName = $this->getFontName($this->pdfRpt,"title",$this->language);
$this->NormalFontName = $this->getFontName($this->pdfRpt,"normal",$this->language);
$this->TitleSize = 13;
$this->NormalSize = 8;
$this->BaseFontName = $this->pdfRpt->_findfont("Times-Roman","host",0);
} //»ñÈ¡´Ë±¨±í×ÖÌå
function getFontName($pdfodj,$fontType,$tmpLang){ //×¢ÒâÏÖÔÚÏȶ¨ÒåÁË5ÖÖÓïÑÔ,»¹½«Ôö¼Ó.
switch ($tmpLang){
case "en":
if ($fontType=="title"){
return $pdfodj->_findfont("Times-Bold","host",0);
}else if ($fontType=="normal"){
return $pdfodj->_findfont("Times-Roman","host",0);
}
break;
case "zhcn":
return $pdfodj->_findfont("STSong-Light","GB-EUC-H",0);
break;
case "zhtw":
return $pdfodj->_findfont("MSung-Light","B5pc-H",0);
break;
case "ja":
return $pdfodj->_findfont("HeiseiKakuGo-W5","83pv-RKSJ-H",0);
break;
case "ko":
return $pdfodj->_findfont("HYGoThic-Medium","KSC-EUC-H",0);
break;
default:
if ($fontType=="title"){
return $pdfodj->_findfont("Times-Bold","host",0);
}else if ($fontType=="normal"){
return $pdfodj->_findfont("Times-Roman","host",0);
}
break;
}//End switch. }//End function. //´´½¨Ò»¸öеı¨±í
function createRpt($fieldname,$fieldwidth,$fielddata,$lang,$showLang,$dir="NULL"){ global $rpttxt; $this->FieldName = $fieldname;
$this->FieldWidth = $fieldwidth;
$this->FieldData = $fielddata;
$this->language = $lang;
$this->showLanguage = $showLang; //Create a Report.
$this->pdfRpt = new PCpdf();
if ($dir=="NULL"){
$this->filepath = $this->ReportID.".pdf";
}else{
$tmpdir=substr($dir,strlen($dir)-1,1);
if (($tmpdir == "/") or ($tmpdir == "\\"))
$this->filepath = $dir.$this->ReportID.".pdf";
else
$this->filepath = $dir."/".$this->ReportID.".pdf";
}
$this->pdfRpt->_open_file($this->filepath); //Set page information.
$this->pdfRpt->_set_info("Author",$rpttxt[0]);
$this->pdfRpt->_set_info("Title",$this->RptTitle);
$this->pdfRpt->_set_info("Creator",$rpttxt[0]);
$this->pdfRpt->_set_info("Subject",$rpttxt[1]); //±¨±í³õʼ»¯
$this->init(); }//End createRpt().
//´´½¨±¨±íÍ·
function createRptHeader(){ global $rpttxt; //Print title
if ($this->language == "en"){
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->TitleFontName,$this->TitleSize);
$x1=$this->outLeft;
$y1=$this->Height - $this->outTop - 40;
$this->pdfRpt->_show_boxed($this->RptTitle,$x1,$y1,$this->Width - $this->outRight*2,40,"center");
$this->pdfRpt->_restore();
}else{
$tmpTitle = explode("\n",$this->RptTitle);
$base_y = 20;
for ($i=0;$i<count($tmpTitle);$i++){
$strlen = strlen($tmpTitle[$i]) * 10;
$pos_x = ($this->Width / 2) - ($strlen / 2);
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->TitleFontName,$this->TitleSize);
$y1=$this->Height - $this->outTop - $base_y;
$this->pdfRpt->_show_xy($tmpTitle[$i],$pos_x,$y1);
$this->pdfRpt->_restore();
$base_y+=20;
}//End for.
}
//Print Date
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->TitleFontName,$this->NormalSize);
$x1=$this->outLeft;
$y1=$this->Height - $this->outTop - 40;
$this->pdfRpt->_show_xy($rpttxt[2].":",$x1,$y1);
$this->pdfRpt->_restore();
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->BaseFontName,$this->NormalSize);
$this->pdfRpt->_show_xy(date("Y-m-d"),$x1+50,$y1);
$this->pdfRpt->_restore();
//End Print Date
//Print Time
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->TitleFontName,$this->NormalSize);
$x1=$this->outLeft;
$y1=$this->Height - $this->outTop - 55;
$this->pdfRpt->_show_xy($rpttxt[4].":",$x1,$y1);
$this->pdfRpt->_restore(); $this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->BaseFontName,$this->NormalSize);
$this->pdfRpt->_show_xy(date("H:i:s"),$x1+50,$y1);
$this->pdfRpt->_restore();
//End Print Time
//Print Audit Data
if (strtoupper($this->AuditDate) != "NULL"){
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->TitleFontName,$this->NormalSize);
$x1=$this->outLeft;
$y1=$this->Height - $this->outTop - 70;
$this->pdfRpt->_show_xy($rpttxt[5].":",$x1,$y1);
$this->pdfRpt->_restore(); $this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->BaseFontName,$this->NormalSize);
$this->pdfRpt->_show_xy($this->AuditDate,$x1+50,$y1);
$this->pdfRpt->_restore();
}
//Print Audit Data
//Print Page
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->TitleFontName,$this->NormalSize);
$x1=$this->Width - $this->outLeft - $this->outRight - 30;
$y1=$this->Height - $this->outTop - 40;
$this->pdfRpt->_show_xy($rpttxt[3].":".$this->CurrPageNum,$x1,$y1);
$this->pdfRpt->_restore(); //Hotel Name
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->NormalFontName,$this->NormalSize);
if ($this->language == "en"){
$x1=$this->Width - $this->outLeft - $this->outRight - 85;
}else{
$x1=$this->Width - $this->outLeft - $this->outRight - 190;
}
$y1=$this->Height - $this->outTop - 65;
$this->pdfRpt->_show_xy($this->HotelName,$x1,$y1);
$this->pdfRpt->_restore();
//Line
$this->pdfRpt->_save();
$this->pdfRpt->_setlinewidth(2);
$y1=$this->Height - $this->outTop - 75;
$this->pdfRpt->_moveto($this->outLeft,$y1);
$this->pdfRpt->_lineto($this->Width - $this->outRight,$y1);
$this->pdfRpt->_stroke();
$this->pdfRpt->_restore();
//Title
if ($this->headerCounts == 1){
$x = $this->outLeft;
for ($i=0;$i<$this->dataColsCounts;$i++){
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->TitleFontName,$this->NormalSize);
$y=$this->Height - $this->outTop - 85;
$this->pdfRpt->_show_xy($this->FieldName[1][$i],$x,$y);
$this->pdfRpt->_restore();
$x += $this->FieldWidth[$i];
}
}else{
$y=$this->Height - $this->outTop - 85;
for ($o=1;$o<=$this->headerCounts;$o++){
$x = $this->outLeft;
for ($i=0;$i<$this->dataColsCounts;$i++){
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->TitleFontName,$this->NormalSize);
$this->pdfRpt->_show_xy($this->FieldName[$o][$i],$x,$y);
$this->pdfRpt->_restore();
$x += $this->FieldWidth[$i];
}
$y-=12;
}
} //Line
$this->pdfRpt->_save();
$this->pdfRpt->_setlinewidth(2);
$y1=$this->Height - $this->outTop - $this->HeaderHeight + $this->RowsHeight;
$this->pdfRpt->_moveto($this->outLeft,$y1);
$this->pdfRpt->_lineto($this->Width - $this->outRight,$y1);
$this->pdfRpt->_stroke();
$this->pdfRpt->_restore(); }//End createRptHeader(). //´´½¨±¨±íÄÚÈÝ
function createRptDetail(){
$addy = $this->HeaderHeight;
while ($this->CurrRecNums < $this->dataRowsCounts){
if (($this->CurrRecNums - $this->PageOfRowsCounts*$this->CurrPageNum) < 0){
$x = $this->outLeft;
$y=$this->Height - $this->outTop - $addy;
for ($i=0;$i<$this->dataColsCounts;$i++){ $var=$this->FieldData[$this->CurrRecNums][$i];
if ($var == "-" && is_string($var)){
$this->pdfRpt->_save();
$this->pdfRpt->_moveto($x,$y);
if ($i == $this->dataColsCounts-1){
$this->pdfRpt->_lineto($x + $this->FieldWidth[$i] - $this->outRight*2,$y);
}else{
$this->pdfRpt->_lineto($x + $this->FieldWidth[$i],$y);
}
$this->pdfRpt->_stroke();
$this->pdfRpt->_restore();
$x += $this->FieldWidth[$i]; }else{
if (strtoupper($this->showLanguage[$i]) == "YES"){
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->NormalFontName,$this->NormalSize);
$this->pdfRpt->_show_xy($this->FieldData[$this->CurrRecNums][$i],$x,$y);
$this->pdfRpt->_restore();
}else{
$this->pdfRpt->_save();
$this->pdfRpt->_setfont($this->BaseFontName,$this->NormalSize);
$this->pdfRpt->_show_xy($this->FieldData[$this->CurrRecNums][$i],$x,$y);
$this->pdfRpt->_restore();
}//End if.
$x += $this->FieldWidth[$i];
}//End if. }
$addy += $this->RowsHeight;
}else{
return false;
} $this->CurrRecNums++;
}
}//End createRptDetail(). //¹Ø±Õ PDF Îļþ
function closeRpt(){
$this->pdfRpt->_close();
}//End closeRpt(). //ÏÔʾ±¨±í
function ShowRpt(){
for ($this->CurrPageNum;$this->CurrPageNum<=$this->PageCounts;$this->CurrPageNum++){
$this->pdfRpt->_begin_page($this->Width,$this->Height);
$this->createRptHeader();
$this->createRptDetail();
$this->pdfRpt->_end_page();
} $this->closeRpt();
$len = filesize($this->filepath);
header("Content-type: application/pdf");
header("Content-Length: $len");
readfile($this->filepath);
$this->pdfRpt->_delete();
}}//End class.?>