Useful functions?
Posted: Wed May 18, 2005 2:38 am
Hello again guys,
I have here some functions I used to generate most of HTML elements such as tables,list,images, etc.
When I want to create a table structure I would do this...
Will you please give some comment regarding these routines or suggestions on better approach.
Thanks.
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 '';
}Code: Select all
echo
TABLE( TR( TD("Name:").
TD(Bold("Harrison"))).
TR( TD("Work:").
TD("Snatcher"))
,array('border'=>0','cellspacing'=>0));Thanks.