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

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

[转]类与PHP (III)

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";

}

?>





返回类别: 教程
上一教程: 新闻发布系统 (例子) 二 dbconn
下一教程: 不使用OCI8接口如何连接PHP和Oracle

您可以阅读与"[转]类与PHP (III)"相关的教程:
· 第七节--类的静态成员 -- PHP5的类与对象 [7]
· 第十五节--ZEND引擎的发展 -- PHP5的类与对象 [15]
· [转]类与PHP (II)
· [转]类与PHP (IV)
· [转]类与PHP (I)
    微笑服务 优质保证 索取样品