Page 1 of 1

HTML Classes

Posted: Sat Oct 26, 2002 7:54 pm
by jamal
Hi,
Please i wondered if anyone out there could
just pity my life in php and do the correction for me??
I am just trying to get my kindergarten of php into
understanding of how to use an html_class in php.
Please do.
Thanks
Mo jam


[ php]
<?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() {

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

}

function TextOut($message="&nbsp") {

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

}

?>
[ /php]

Posted: Sat Oct 26, 2002 8:40 pm
by volka
use indents and you will see that some curly brackets are at the wrong place. If your project gets more complex comments get quite handy.

Code: Select all

&lt;?php
class example
{
	/** myVar: if no comment for something comes to your mind, maybe
		it is useless 
	*/
	var myVar;

	/** constructor for class example
		sets all member var.s to valid defaults
	*/
	function example() 
	{
		myVar = 0;
		// ...
	} // end of function example

	/** calculates the square of member myVar
		@returns Integer, myVar*myVar
	*/
	function square()
	{
		return (int)myVar*(int)myVar;
	} // end of function square
 ...
} // end of class example	
?&gt;
if I get stucked in a project I review my comments or (if not already done) I start to comment at least the part that seems to cause errors. I found this very useful in finding bugs

Posted: Sun Oct 27, 2002 1:45 am
by Takuma
Or you could use a syntax highliting software to edit PHP codes.

Posted: Sun Oct 27, 2002 2:18 am
by volka
And that shows paired brackets (like i.e. phpEdit does)

Posted: Sun Oct 27, 2002 4:43 am
by Takuma
If you want a good PHP editor search this forum for it, I think there are about 5 threads which talked about it in the General Forum.

HTML_Class

Posted: Sun Oct 27, 2002 8:02 am
by jamal
Hi,
Please can anyone still explain why i get an error at the last line where i declared the function??
I need help.



<?php

class Style
{

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

// you closed off the class at this bracket,
//there for you prolly got a error saying "call to a undefined object or something"
// }
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;

}

// did it again
// }

function Body()
{

// just use echo im not looking through this, im just showing you the proper structure for the class
echo "<BODY BGCOLOR=\"$this->bgcol\" ".
"TEXT=\"$this->text\" ".
"LINK=\"$this->link\" VLINK=\"$this->vlink\" ".
"ALINK=\"$this->alink\"><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";

}
}
// we close off the class, now we have to activate it.

$style_class = new Style;

$style_class->function(arguments); // an error here

?>

Posted: Sun Oct 27, 2002 8:59 am
by twigletmac
What exactly is the error?

Mac

Posted: Sun Oct 27, 2002 2:48 pm
by twigletmac
Please stop posting multiple threads about the same problem - from now on just post everything relevant to this here.

http://www.devnetwork.net/forums/viewtopic.php?t=3899
http://www.devnetwork.net/forums/viewtopic.php?t=3925

Mac