HTML Classes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

HTML Classes

Post 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]
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Or you could use a syntax highliting software to edit PHP codes.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

And that shows paired brackets (like i.e. phpEdit does)
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post 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.
jamal
Forum Commoner
Posts: 57
Joined: Sat Oct 26, 2002 7:53 pm
Location: London

HTML_Class

Post 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

?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What exactly is the error?

Mac
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply