Page 1 of 1

Useful functions?

Posted: Wed May 18, 2005 2:38 am
by harrisonad
Hello again guys,

I have here some functions I used to generate most of HTML elements such as tables,list,images, etc.

Code: Select all

// ------------ sample functions-------------------
function TABLE($content,$properties='') { return Encaps('TABLE',$content,$properties);}
function TR($content,$properties='')    { return Encaps('TR',$content,$properties);}
function TD($content,$properties='')    { return Encaps('TD',$content,$properties);}
function BOLD($content)                 { return Tag('B',$content);}

// ----------- base functions ----------------------
function Encaps($tag,$content,$properties=''){
    return "\n<$tag".PropertyParse($properties).">$content</$tag>";
}
function Tag($tag,$properties){
    return "<$tag ".PropertyParse($properties).">";
}
function PropertyParse($properties){
    if(is_array($properties)){
        $propstr = "";
        foreach($properties as $property=>$value){
            $propstr .= " $property=$value";
        }
        return $propstr;
    }else
        return '';
}
When I want to create a table structure I would do this...

Code: Select all

echo 
TABLE( TR( TD("Name:").
           TD(Bold("Harrison"))).
       TR( TD("Work:").
           TD("Snatcher"))
    ,array('border'=>0','cellspacing'=>0));
Will you please give some comment regarding these routines or suggestions on better approach.

Thanks.

Posted: Wed May 25, 2005 5:00 pm
by thomas777neo
I like it

The only problem that I have with it is that I would be a nightmare for a graphics / web designer in a development team.

Posted: Wed May 25, 2005 5:07 pm
by Skara
Yeah, it's pretty nice. IPB uses a similar method in the ACP. I liked the way they did it better, though. Something like...

Code: Select all

tr('td one','td two','td three');
*shrugs* Whatever works, though. ;)