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

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

[转]类与PHP (V)

Classes and PHP

Let\\'s do the table body now:

<TR>
<?php

$Tbody->TDOut("Kreisler");
$Tbody->TDOut("Rod");
$Tbody->TDOut("Cortlandt");
$Tbody->TDOut("New York");
$Tbody->TDOut("USA");
?>
</TR>

But this is still getting kind of lengthy. Couldn\\'t we save some more steps? How about trying this:

<?php

function TROut($message) { /*And NO comments about fish, please! ;)   */

        PRINT "<TR>/n";
        $cells=explode("|",$message);
        $iterations=count($cells);
        $i=0;
        while ($i<$iterations) {
                list($message,$span)=explode(":",$cells[$i]);
                if (strlen($message)<1) $message=" ";
                if ($span){
                        $this->TDOut ($message,$span);
                }else{
                        $this->TDOut ($message);
                }
                $i++;
                }
        PRINT "</TR>/n";

}

?>

Wow! That\\'s a little more complicated. Let\\'s break it down:

Line 3 splits the message on pipes and stores the pieces in the array $cells. Line 4 stores the number of items (number of cells) in $iterations. Line 6 begins our loop to go through these cell items. Line 7 splits the cell data at the colon and stores them into the variables $message and $span. Line 8 checks to see if a message was included. If not then it sets message to the default. Line 9 checks to see if there was a span listed (i.e. the cell data had a colon with something behind it. if so, Line 10 calls TDOut with the message and the number of cells it spans. if not, Line 12 calls TDOut with just the message (TDOut will set $colspan to the default 1). Lastly, we close out the row.

What this means is we can pass a single string to TROut that will contain all the necessary information to print out the entire row as long as the string is in the format "celldata[:colspan]|celldata[:colspan]|......celldata[:colspan]".

So, instead of all the work we did before, the headers and body of the table could be called like this:

<TABLE>
<?
$Theader->TROut("Name:2|Address:3");
$Theader->TROut("First|Last|City|State/Province|Country");
$Tbody->TROut("Rod|Kreisler|Cortlandt|New York|USA");
?>
</TABLE>

Wow. That\\'s a lot easier. But what if the data is in variables? Simply join the array:

<?php

$message=join($arry,"|");
$Tbody->TROut($message);

?>





返回类别: 教程
上一教程: PHP中如何增加一个系统用户
下一教程: 我错了。。是我不好。。呜呜。。负荆请罪。。(转载一篇好文章:PHP4 的新函数介绍 - 输出信息控制函数)

您可以阅读与"[转]类与PHP (V)"相关的教程:
· 第十一节--重载 -- PHP5的类与对象 [11]
· 第三节--定义一个类 -- PHP5的类与对象 [3]
· 第四节--构造函数和析构函数 -- PHP5的类与对象 [4]
· 第八节--访问方法 -- PHP5的类与对象 [8]
· [转]类与PHP (IV)
    微笑服务 优质保证 索取样品