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.
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器