欢迎光临
我们一直在努力

[转]类与PHP (IV)-PHP教程,PHP应用

建站超值云服务器,限时71元/月

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 isnt 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 havent 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 doesnt 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, were 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 its 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.

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » [转]类与PHP (IV)-PHP教程,PHP应用
分享到: 更多 (0)