Useful functions?

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
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Useful functions?

Post 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.
User avatar
thomas777neo
Forum Contributor
Posts: 214
Joined: Mon Mar 10, 2003 6:12 am
Location: Johannesburg,South Africa

Post 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.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post 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. ;)
Post Reply