快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

[转]类与PHP (IV)

Classes and PHP

This function will take a message passed in the argument and print it out in the appropriate style object. So to print a message we can:

<?php

$Basic->TextOut(\\'This is my test message\\');
$Tbody->TextOut(\\' -- kinda neat, huh?\\');

?>

Notice, there are no <BR> between the two function calls so they will print on the same line. Also, I just wanted a smaller font for the second part of the output and I had already declared that in $Tbody so I used that. This is safe in this instance as the only other difference between $Basic and $Tbody is "bgcol" and that isn\\'t used in this function. Notice the " " in the function declaration? That is there so if no message is passed the function will print out a non- breaking space. Why will become clear later on.

So far we haven\\'t saved a lot of work. The last example is easier if you want to change font color and/or size in the middle of a sentence but still doesn\\'t justify writing an entire class. How about we add to the functions:

<?php

function TDOut ($message=" ",$colspan=1) {

        PRINT "<TD COLSPAN=$colspan BGCOLOR=/"$this->bgcol/" ".
                "ALIGN=/"$this->align/" VALIGN=/"$this->valign/">";
        $this->TextOut($message);
        PRINT "</TD>/n";

}

?>

Now, we\\'re getting somewhere! Remember, I wanted to have different background colors for my tables. Now I can do this:

<TABLE>
<TR>
<?php

$Theader->TDOut("Name",2);
$Theader->TDOut("Location",3);

?>
</TR>
<TR>
<?php

$Theader->TDOut("Last");
$Theader->TDOut("First");
$Theader->TDOut("City");
$Theader->TDOut("State/Province");
$Theader->TDOut("Country");

?>
</TR>

There. See how the colspan argument works. If it\\'s not declared it defaults to 1. So in the first table row "Name" spans 2 columns and "Location" spans 3. In the second row all of them cover a single column.





返回类别: 教程
上一教程: 超越模板引擎
下一教程: date.inc.php3中两个函数的例程。

您可以阅读与"[转]类与PHP (IV)"相关的教程:
· [转]类与PHP (V)
· 第二节--PHP5 的对象模型 -- PHP5的类与对象 [2]
· [转]类与PHP (I)
· 第八节--访问方法 -- PHP5的类与对象 [8]
· 第一节--面向对象编程 -- PHP5的类与对象 [1]
    微笑服务 优质保证 索取样品