动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
   PHP → 阅读文章

 [转]类与PHP (IV)

作者来源: 
阅读 959 人次 , 2006-4-18 17:24:00 


   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.   
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:[转]类与PHP (III)
· 下一篇:[转]类与PHP (V)
· 如何统计在线人数
· 不使用OCI8接口如何连接PHP和Oracle
· 网络资源
· 如何用PHP把RDF内容插入Web站点之中(6)
· SNMP 网管函数库


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077