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

 [转]类与PHP (III)

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


   Classes and PHP

Great, now what to we do with it? I'm glad you asked. We need to create a few more functions within Style to actually accomplish anything. The first thing I'd like to do is set up my page body so I did this:

<?php

function Body() {

        PRINT "<BODY BGCOLOR=\"$this->bgcol\" ".
                "TEXT=\"$this->text\" ".
                "LINK=\"$this->link\" VLINK=\"$this->vlink\" ".
                "ALINK=\"$this->alink\"><FONT ".
                "FACE=\"$this->face\" SIZE=$this->size>\n";

}

?>

This sets up the page body for us. It also illustrates a new variable "$this." When used inside of a class function it lets the interpreter know we are referring to a variable of THIS instance. In other words, it's assigned the value of the name of the instance in the calling line (e.g. $this would be == $Basic when $Basic->Body() is the calling statement.) Also, notice we are doing something here that's much simpler than is possible in regular functions. We're referring to variables that were not passed to the function. Remember, all functions and variables of an instance are available to all functions of that instance. To do this with regular functions you'd have to set up several global arrays.

Try this in your php script (assuming you've included the Style class, created the style objects above and sent the <HTML> and <HEAD></HEAD> tags):

<?php $Basic->Body(); ?>

Now, we're ready to print something out. We could do it the old fashioned way, but I'm going to do something different... that's right another function:

<?php

function TextOut($message=" ") {

        PRINT "<FONT FACE=\"$this->face\" ".
                "SIZE=$this->size COLOR=\"$this-> ".
                "text\">$message</FONT>\n";

}

?>   
 
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:[转]类与PHP (II)
· 下一篇:[转]类与PHP (IV)
· 动态生成gif格式的图像要注意?
· 一个php作的文本留言本的例子(二)
· 将一个数字的十位和个位对调及所想到
· [精]任何数据存入mysql,及从中提取的程序
· PHP5在Apache下的两种模式的安装


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