www.phpclasses.org 这个网站中类多的象米一样。

解决方案 »

  1.   

    土八路你的网址无法访问的.给你一篇不错的文章我想你看过以后就可以理解类了.
    http://www.cngnu.org/technology/0584/207.html
      

  2.   

    我写了一个简单的不能再简单的类.相信你会看懂的.<?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就这么简单.依我理解.类就是一个函数的聚合罢了.比较适合像我这种比较懒的人..嘿嘿
      

  3.   

    <?php/*
    &para;à&Oacute;&iuml;&Ntilde;&Ocirc;&Ouml;§&sup3;&Ouml; PDF &Icirc;&Auml;&frac14;&thorn;&Eacute;è&frac14;&AElig;&AElig;÷
    */
    class PMultLanguagePDF extends PCpdf { //&sup1;&sup1;&Ocirc;ì&ordm;&macr;&Ecirc;&yacute;&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;±&auml;&Aacute;&iquest;
    var $ReportID,$RptTitle,$AuditDate,$RptType,$Width,$Height,$TitleFontName,$NormalFontName,$TitleSize,$NormalSize,$HotelName; //&para;¨&Ograve;&aring;±¨±í&Oacute;&iuml;&Ntilde;&Ocirc;&ordm;&Iacute;&raquo;ù±&frac34;×&Ouml;&Igrave;&aring;,&Ecirc;&Ccedil;·&ntilde;&Iuml;&Ocirc;&Ecirc;&frac34;&acute;&Euml;&Oacute;&iuml;&Ntilde;&Ocirc;
    var $language,$BaseFontName,$showLanguage; //&para;¨&Ograve;&aring;&sup2;&Ugrave;×÷&frac34;&auml;±ú
    var $pdfRpt; //&para;¨&Ograve;&aring;&acute;ò&Oacute;&iexcl;&Ograve;&sup3;&Atilde;&aelig;&Euml;&Auml;±&szlig;&frac34;à
    var $outTop,$outBottom,$outLeft,$outRight; //&Icirc;&Auml;&frac14;&thorn;&micro;&Auml;&Egrave;&laquo;&Acirc;·&frac34;&shy;
    var $filepath; //&para;¨&Ograve;&aring;&Ecirc;&yacute;&frac34;&Yacute;&frac14;&macr;&ETH;&ETH;&Ecirc;&yacute;&iexcl;&cent;&Aacute;&ETH;&Ecirc;&yacute;,&Ograve;&sup3;×&Uuml;&Ecirc;&yacute;,&micro;±&Ccedil;°&Ograve;&sup3;&Acirc;&euml;,&Atilde;&iquest;&Ograve;&sup3;×&icirc;&para;à&iquest;&Eacute;&Ograve;&Ocirc;&Iuml;&Ocirc;&Ecirc;&frac34;&micro;&Auml;&frac14;&Ccedil;&Acirc;&frac14;&Ecirc;&yacute;,&micro;±&Ccedil;°&Ograve;&Ocirc;&Iuml;&Ocirc;&Ecirc;&frac34;&micro;&frac12;&micro;&Auml;&frac14;&Ccedil;&Acirc;&frac14;&Ecirc;&yacute;,±¨±í&Iacute;·&micro;&Auml;&cedil;&szlig;&para;&Egrave;,±¨±í&Iacute;·&micro;&Auml;&ETH;&ETH;&Ecirc;&yacute;
    var $dataRowsCounts,$dataColsCounts,$PageCounts,$CurrPageNum,$PageOfRowsCounts,$CurrRecNums,$HeaderHeight,$headerCounts;

    //&ETH;&ETH;&frac14;&auml;&frac34;à
    var $RowsHeight = 13; //×&Ouml;&para;&Icirc;&micro;&Auml;±ê&Igrave;&acirc;&Atilde;&ucirc;&sup3;&AElig;&pound;&not;&iquest;í&para;&Egrave;&pound;&not;&Ecirc;&yacute;&frac34;&Yacute;.
    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;

    //&Aring;&ETH;&para;&Iuml;&Ecirc;&Ccedil;&Ecirc;ú&acute;ò&Oacute;&iexcl;&raquo;&sup1;&Ecirc;&Ccedil;&ordm;á&acute;ò&Oacute;&iexcl;
    if ($rpttype == "VERTICAL"){
    $this->Width = $width;
    $this->Height = $height;
    }else if ($rpttype == "HORIZONTAL"){
    $this->Width = $height;
    $this->Height = $width;
    } }//End PSimplePDFDesigner($reportid).
    //&Eacute;è&Ouml;&Atilde;&acute;ò&Oacute;&iexcl;&Ograve;&sup3;&Atilde;&aelig;&Euml;&Auml;±&szlig;&frac34;à
    function setOutPage($top,$bottom,$left,$right){
    $this->outTop = $top;
    $this->outBottom = $bottom;
    $this->outLeft = $left;
    $this->outRight = $right;
    } //±¨±í&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;
    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; //&sup1;&Oslash;&Oacute;&Uacute;×&Ouml;&Igrave;&aring;&Ouml;&Ouml;&Agrave;à&frac14;°&acute;ó&ETH;&iexcl;
    $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);
    } //&raquo;&ntilde;&Egrave;&iexcl;&acute;&Euml;±¨±í×&Ouml;&Igrave;&aring;
    function getFontName($pdfodj,$fontType,$tmpLang){ //×&cent;&Ograve;&acirc;&Iuml;&Ouml;&Ocirc;&Uacute;&Iuml;&Egrave;&para;¨&Ograve;&aring;&Aacute;&Euml;5&Ouml;&Ouml;&Oacute;&iuml;&Ntilde;&Ocirc;,&raquo;&sup1;&frac12;&laquo;&Ocirc;&ouml;&frac14;&Oacute;.
    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. //&acute;&acute;&frac12;¨&Ograve;&raquo;&cedil;&ouml;&ETH;&Acirc;&micro;&Auml;±¨±í
    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]); //±¨±í&sup3;&otilde;&Ecirc;&frac14;&raquo;&macr;
    $this->init(); }//End createRpt().
    //&acute;&acute;&frac12;¨±¨±í&Iacute;·
    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
      

  4.   

    续一个PDF文档生成的类
    //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(). //&acute;&acute;&frac12;¨±¨±í&Auml;&Uacute;&Egrave;&Yacute;
    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(). //&sup1;&Oslash;±&Otilde; PDF &Icirc;&Auml;&frac14;&thorn;
    function closeRpt(){
    $this->pdfRpt->_close();
    }//End closeRpt(). //&Iuml;&Ocirc;&Ecirc;&frac34;±¨±í
    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.?>