p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

beginning_php thread: using class in php


Message #1 by "Jamal" <new_mojam@y...> on Thu, 31 Oct 2002 06:03:43
Hi ,
I am still finding myself lock up because I don't know it fully. I have a 
file below used as html_class.inc. I included it in file called 
index.html. Now how can I call the function to print the bgcolor, link, 
vlink, alink and the rest of the attributes please?
here is the code: 


<?php  

class Style 
{  
   var $text;  
   var $alink;  
   var $vlink;  
   var $link;  
   var $bgcol;  
   var $face;  
   var $size;  
   var $align;  
   var $valign;  

   function Style($text="#CCCCFF", $alink="#AA00AA", $vlink="#AA00AA", 
$link="#3333FF", $bgcol="#999999", $face="Book Antiqua", $size=3, 
$align="CENTER", $valign="TOP") 
   { 
      $this->text=$text;  
      $this->alink=$alink;  
      $this->vlink=$vlink;  
      $this->link=$link;  
      $this->bgcol=$bgcol;  
      $this->face=$face;  
      $this->size=$size;  
      $this->align=$align;  
      $this->valign=$valign;  
   }  

   function Body() {  
      echo "<body bgcolor=\"{$this->bgcol}\" text=\"{$this->text}\" 
link=\"{$this->link}\" vlink=\"{$this->vlink}\" alink=\"{$this->alink}
\">\n <font face=\"{$this->face}\" size=\"{$this->size}\">\n";  
   }  

   function TextOut($message="&nbsp") 
   {  
      echo "<font face=\"{$this->face}\" size=\"{$this->size}\" 
color=\"{$this->text}\">{$message}</font>\n";  

   } 
} 

?>

Message #2 by "Nikolai Devereaux" <yomama@u...> on Thu, 31 Oct 2002 10:24:52 -0800
Let's assume that your Style class is defined in a file called
"Style.class.php".  Here's how you'd use it:


<?php

require_once('Style.class.php');

$style = new Style();

$style->Body();
$style->TextOut("Hello, world");

?>


take care,

nik


  Return to Index