Version: 1.0

Type: Function

Category: HTML

License: GNU Library Public License

Description: Set of functions to generate HTML Tags such as Table, tr, html, body, etc through easy interface like Start_Table, End_Table, Start_Td, End_Td. Main advantage of this is, it can be EASILY EXPANDABLE to support any tag.



/** VPK
* HTML Writer 1.0
* Author: S.Murali Krishnan <smk_bk@yahoo.com>
* Copyright (C) 2001-2002 S.Murali Krishnan 
*
* Usage and Documentation for this file would be present in "htmlwriter.txt"
* which would be come along with this file.
*
* Report any Bugs or queries regarding usage and code logic
* to  <smk_bk@yahoo.com>, I will try my best to answer them.
*
* Though I cannot upload this file as tgz or zip. I'm providing the
* documentation  file as comment at the bottom of this file.
* To EXTRACT The documentation , comment out the TEST CODE at the bottom,
* and run this program using PHP so that documentation alone could be
* extracted as output.
*/
<?php

/*  Html Tags Configurations */

    $HtmlEndl = "<br/>" ; // HTML Newline Tag
    $endl     = "\n"    ; // Your System's Newline character

    $Body = array( 
                      "start_tag"   => "<body>",
                      "end_tag"     => "</body>",
                      "background"  => "",
                      "bgcolor"     => "#A8AAF7",
                      "text"        => "",
                      "link"        => "",
                      "alink"       => "",
                      "vlink"       => "",
                      "style"       => "",
                      "lang"        => "" 
                    );
    $Center = array( 
                     "start_tag"    => "<center>",
                     "end_tag"      => "</center>"
                  );
    $Img    = array(
                      "start_tag"    => "<img>",
                      "src"          => "",
                      "height"       => "",
                      "width"        => "",
                      "alt"          => "image",
                      "align"        => "center",
                      "border"       => 0,
                      "supress"      => "false",
                      "hspace"       => "",
                      "vspace"       => ""
                    );
    $Hr     = array(
                     "start_tag"     => "<hr>",
                     "align"         => "center",
                     "width"         => "100%",
                     "size"          => "3",
                     "others"        => "noshade"
                    );
    $A      = array(
                     "start_tag"     => "<a>",
                     "end_tag"       => "</a>",
                     "name"          => "",
                     "href"          => "",
                     "target"        => "_self"
                    );

    $Table      = array(
                       "start_tag"   => "<table>",
                       "end_tag"     => "</table>",
                       "width"       => "100%",
                       "height"      => "",
                       "border"      => $border,
                       "bgcolor"     => "#f1daba",
                       "style"       => "",
                       "class"       => "",
                       "cellpadding" => "0",
                       "cellspacing" => "0",
                       "align"       => "center",
                       "valign"      => "middle",
                       "others"      => "" 
                      );
    $Tr       = array(
                      "start_tag"    => "<tr>",
                      "end_tag"      => "</tr>",
                      "width"        => "",
                      "height"       => "",
                      "bgcolor"      => "#f1daba",
                      "style"        => "",
                      "align"        => "",
                      "valign"       => "",
                      "others"       =>  "",
                      "border"       => $border
                    );

    $Td       = array(
                      "start_tag"    => "<td>",
                      "end_tag"      => "</td>",
                      "width"        => "",
                      "height"       => "",
                      "bgcolor"      => "#f1daba",
                      "style"        => "",
                      "align"        => "",
                      "valign"       => "",
                      "colspan"      => "",
                      "others"       => ""
                     );
    $Font   = array(
                    "start_tag"      => "<font>",
                    "end_tag"        => "</font>",
                    "style"          => "",
                    "weight"         => "",
                    "size"           => "3pt",
                    "border"         => "",
                    "color"          => "darkred",
                    "others"         => "",
                    "text"           => "",
                    "face"           => "helvetica"
                  );

    $Link   = array(
                    "rel"            => "stylesheet", 
                    "type"           => "text/css",
                    "src"            => ""
                  );
    $Frame  = array(
                    "start_tag"      => "<frame>",
                    "end_tag"        => "</frame>",
                    "bordercolor"    => "color",
                    "frameborder"    => "yes",
                    "marginheight"   => "5",
                    "marginwidth"    => "5",
                    "name"           => "framename",
                    "scrolling"      => "yes",
                    "src"            => "index.php",
                    "others"         => "noresize"
                  );
    $Frameset = array(
                    "start_tag"      => "<frameset>",
                    "end_tag"        => "</frameset>",
                    "cols"           => "",
                    "rows"           => "100%",
                    "border"         => "2",
                    "bordercolor"    => "",
                    "frameborder"    => "yes"
                   );

   $Layer     = array(
                    "start_tag"      => "<layer>",
                    "end_tag"        => "</layer>",
                    "id"             => "layername",
                    "left"           => "",
                    "top"            => "",
                    "pagex"          => "",
                    "page"           => "",
                    "src"            => "file",
                    "z-index"        => "0",
                    "above"          => "",
                    "below"          => "",
                    "width"          => "",
                    "height"         => "",
                    "clip"           => "",
                    "visibility"     => "",
                    "bgcolor"        => "",
                    "background"     => ""
                   );

/* End Html Tags Configurations */

/* Form related Tags Configuration */

    $Form   = array( 
                    "start_tag"      => "<form>",
                    "end_tag"        => "</form> ",
                    "name"           => "some",
                    "action"         => "something.php",
                    "method"         => "post",
                    "target"         => "_self",
                    "others"         => ""
                  );

    // common for text, password, file
    $TxtBox  = array(
                     "start_tag"     => "<input>",
                     "type"          => "text",
                     "name"          => "",
                     "value"         => "",
                     "size"          => 10,
                     "maxlength"     => "",
                     "others"        => ""
                     );
    // common for reset, submit, hidden, image, button, checkbox, radio.
    $Button = array( 
                     "start_tag"     => "<input>",
                     "type"          => "submit",
                     "name"          => "compname",
                     "value"         => "object",
                     "others"        => "" 
                  );
    $SelectBox = array(
                    "start_tag"      => "<select>",
                    "name"           => "",
                    "end_tag"        => "</select>",
                    "height"         => "1",
                    "width"          => "",
                    "others"         => ""
                   );
   $Soption = array( 
                    "start_tag"      => "<option>",
                    "end_tag"        => "</option>",
                    "value"          => "",
                    "text"           => ""
                  );

    $TextArea =  array(
                    "start_tag"      => "<textarea>",
                    "end_tag"        => "</textarea>",
                    "name"           => "",
                    "wrap"           => "hard",
                    "cols"           => "50",
                    "rows"           =>  "7",
                    "value"          =>  ""
                  );

/* End Form Tags Configurations */

/** function to build the tag with its attributes 
* This function is called for every tag function to Build the tag.
* It expects three arguments. 
* SrcArray : Array in which each key and value indicate the
*            attribute key and value of the tag.
* Funcname : Callback function to call for each key value.
* Tag_Var  : reference string variable in which tag have to be built.
*/

function make_tag($SrcArray, $Funcname, $Tag_Var)
{
  if (!is_array($SrcArray)) {
    print "Error: First Argument to make_tag is not an array\n" ;
    return false ;
  }

  if (!function_exists($Funcname)) {
    print "Error: Function $Funcname doesn't exists\n";
    return false ;
  }

  $Tag_Var .= $SrcArray['start_tag'] ;
  unset($SrcArray['start_tag']);

  while (list($key, $value) = each($SrcArray)) {
    call_user_func($Funcname, $value, $key, &$Tag_Var);
  }

  return true ;
}

/** 
* Function to build single attribute and append to the tag.
* it is internally called by make_tag for each attribute.
*/

function  BuildAttribs($val, $key, &$Tag_Var)
{
    if  ($val != "") {

      if ($key == "end_tag") {
        return $Tag_Var ;

      } else if ($key == "others") {

        $Attribute = " $val" ;
        $Tag_Var = substr_replace($Tag_Var, $val, -1, 0);

      } else {

        $Attribute = " $key='$val'" ;
        $Tag_Var = substr_replace($Tag_Var, $Attribute, -1, 0) ;

      }
    }

    return $Tag_Var ; // Though its not necessary.
}

/* Tag Specific function */

/* Functions necessary to output most of the HTML Tags */

function Start_Html()
{
  global $endl ;
  print "<html>" . $endl; 
  return ;
}

function Start_Head()
{
  global $endl ;
  print "<head>" . $endl ;
  return ;
}

function End_Head()
{
  global $endl ;
  print "</head>" . $endl ;
  return ;
}

function Start_Script($lang = "javascript", $src)
{
  global $endl ;
  print "<script language='$lang' " ;

  if ($src != "") {
    print "src='$src' ></script>" . $endl ;
  } else {
    print ">\n<!--\n" . $endl ;
  }

  return true ;
}

function End_Script()
{
  global $endl ;
  print "// -->\n</script>" . $endl ;
  return ;
}

function Start_Style($type = "text/css")
{
  global $endl ;
  print "<style type='$type' >" . $endl ;
  return ;
}

function End_Style()
{
  global $endl ;
  print "</style>"  . $endl ;
  return ;
}

function Out_Link($link)
{
  // possible attribs : rel, type, src 
  // <LINK REL=STYLESHEET TYPE="text/css" SRC="styles/style1.htm">
  if (!is_array($link)){
    return false ; 
  }

  $Link_Tag = "<link>";
  make_tag($link, "BuildAttribs", &$Link_Tag);
  print $Link_Tag . $endl;
  print "</link>" . $endl;

  return ;
}

function Out_Base($basehref)
{
  global $endl;
  print "<base href='$basehref'>". $endl ;
  return ;
}

function Out_title($titlestr = "title of this page")
{
  global $endl;
  print "<title>$titlestr</title>" .$endl ;
  return ;
}

function End_Html()
{
  global $endl ;
  print "</html>" .  $endl ;
}

function Start_Body($LBody = array())
{
  global $endl, $Body ;

  $Body_Tag = "";
  $LBody = array_merge($Body, $LBody);
  make_tag($LBody, "BuildAttribs", &$Body_Tag);
  print $Body_Tag . $endl ;

  return true ;
}

function End_Body()
{
  global $endl, $Body ;
  print $Body["end_tag"] . $endl ;
  return ;
}

function Start_Table($LTable = array())
{
  global $endl, $Table ;
  $Table_Tag = "" ;

    $LTable = array_merge($Table, $LTable);
    make_tag($LTable, "BuildAttribs", &$Table_Tag);
    print $Table_Tag . $endl ;

    return true ;
}

function End_Table()
{
  global $endl, $Table ;
  print $Table["end_tag"] . $endl ;

  return true ;
}

function Start_Tr($LTr = array())
{
  global $endl, $Tr ;
  $Tr_Tag = "" ;

  $LTr = array_merge($Tr, $LTr);
  make_tag($LTr, "BuildAttribs", &$Tr_Tag);
  print $Tr_Tag . $endl ;

  return true;
}

function End_Tr()
{
  global $endl, $Tr ;
  print $Tr["end_tag"] . $endl ;
  return ;
}

function Start_Td($LTd = array())
{
  global $endl, $Td ;

  $Td_Tag  = "" ;

    $LTd = array_merge($Td, $LTd);
    make_tag($LTd, "BuildAttribs", &$Td_Tag);
    print $Td_Tag . $endl ;
}

function End_Td()
{
  global $endl, $Td ;
  print $Td["end_tag"] . $endl ;
  return ;
}

function Draw_Line($LHr = array())
{
  global $endl, $Hr ;
  $Line_Tag = "";

  $LHr = array_merge($Hr, $LHr);
  make_tag($LHr, "BuildAttribs", &$Line_Tag);
  print $Line_Tag . $endl ;
  return ;
}

function Out_Tag($LTag = array())
{
  global $endl ;
  $Tag = "" ;

  if (!is_array($LTag)) {
    print $LTag . $endl ;
    return true ;
  }

    make_tag($LTag, "BuildAttribs", &$Tag);
    print $Tag . $endl ;
}

function Start_Form($LForm = array())
{
  global $Form, $endl ;
  $FormTag = "";

  $LForm   = array_merge($Form, $LForm) ;
  make_tag($LForm, "BuildAttribs", &$FormTag);
  print $FormTag . $endl ;
}

function End_Form()
{
  global $Form, $endl ;
  print $Form["end_tag"] . $endl ;
  return ;
}


function Draw_Input($LText = array())
{
  global $TxtBox, $endl ;
  $TextTag = "";

  $LText = array_merge($TxtBox, $LText);
  make_tag($LText, "BuildAttribs", &$TextTag);
  print $TextTag . $endl ;

}

function Start_Txtarea($LTxtArea = array())
{
  global $TextArea, $endl ;
  $TextAreaTag = "" ;

  $LTxtArea = array_merge($TextArea, $LTxtArea);
  make_tag($LTxtArea, "BuildAttribs", &$TextAreaTag);
  print $TextAreaTag . $endl ;

  return ;
}

function End_TxtArea()
{
  global $TextArea, $endl ;
  print $TextArea["end_tag"] . $endl ;
  return ;
}

function Start_SelectBox($LSelect = array())
{
  global $SelectBox, $endl ;
  $SelectTag = "" ;

  $LSelect =  array_merge($SelectBox, $LSelect);
  make_tag($LSelect, "BuildAttribs", &$SelectTag);
  print $SelectTag . $endl ;

  return ;
}

function Draw_Option($Opt = array(), $sel = 0)
{
  global $Soption, $endl ;
  $Otext = "";
  $Oetag = "" ;
  $OptTag = "";

  $Loption = array_merge($Soption, $Opt);

  $Otext = $Loption['text']  ;

  $Loption['text'] ='' ;
  make_tag($Loption, "BuildAttribs", &$OptTag);

  $OptTag .= $Otext  ;
  $OptTag .= $Soption['end_tag'] ;

  print $OptTag . $endl ;  // printing <option value='xxx' ...>text</option> 

  return ;
}

function Draw_SelOptions($KeyVal = array(), $SelVal = "")
{

    while  (list($key, $val) = each($KeyVal)) {
        $Opt = array( 
                      'text'  => $val,
                      'value' => $key
                    );
      if ($SelVal == $key) {
        $Opt['others'] = 'selected' ;
      }

      Draw_Option($Opt);
    }

    return true ;
}

function End_SelectBox()
{
  global $SelectBox, $endl ;
  print $SelectBox["end_tag"] . $endl ;
  return ;
}

function Draw_Radio($Lradio = array())
{
  global $Button, $endl ;
  $RadioTag = "";

    $LRadio = array_merge($Button, $LRadio);
    make_tag($LRadio, "BuildAttribs", &$RadioTag);
    print $RadioTag . $endl ;

    return ;
}

function Draw_Button($LButton = array())
{
  global $Button, $endl ;
  $ButtonTag = "";

    $LButton = array_merge($Button, $LButton);
    make_tag($LButton, "BuildAttribs", &$ButtonTag);
    print $ButtonTag . $endl ;

    return ;
}

function Draw_Img($LImg = array())
{
  global $endl, $Img ;
  $Img_Tag = "" ;

    $LImg = array_merge($Img, $LImg);
    make_tag($LImg, "BuildAttribs", &$Img_Tag);
    print $Img_Tag . $endl ;

    return;
}

function Start_A($LA = array(), $Hargs = array())
{
  global $endl, $A ;
  $A_Tag = "" ;

  $LA = array_merge($A, $LA);

// If any GET values to be encoded in Url.

  if (($cnt = count($Hargs))) {
    $LA['href'] .= "?" ;
    while (list($key, $value) = each($Hargs)) {
      $i++ ;
      $LA['href'] .=  "$key=" . urlencode($value);
      if ($i < $cnt)
        $LA['href'] .= "&" ;
    }

  }
  make_tag($LA, "BuildAttribs", &$A_Tag);
  print $A_Tag . $endl ;

  return true ;
}

function End_A()
{
  global $A, $endl ;
  print $A['end_tag'] . $endl ;
  return ;
}


/** make font is similar to Draw_Label function, but instead of 
*   printing the font tag it will return the tag after making
*/

function Make_Font($LFont = "")
{
  global $Font, $endl ;
  $FontTag = "" ;

  if (!is_array($LFont))
  {
    print "<font>$LFont</font>" . $endl ;
    return ;
  } 

  $LFont = array_merge($Font, $LFont);

  $LText =  $LFont["text"] ;

  $LFont["text"] = "" ;
  make_tag($LFont, "BuildAttribs", &$FontTag);
  $FontTag .= $LText . $Font['end_tag'] ;

  return  $FontTag ;

}

function Start_Frame($LFrame = "")
{
    global $Frame, $endl ;

    $Frame_Tag = "" ;

    $LFrame = array_merge($Frame, $LFrame);
    make_tag($LFrame, "BuildAttribs", &$Frame_Tag);
    print $Frame_Tag . $endl ;

    return true ;
}

function End_Frame()
{
    global $Frame, $endl ;

    print $Frame['end_tag'] . $endl ;
    return true ;
}

function Start_Layer($LLayer = "")
{
    global $Layer, $endl ;

    $Layer_Tag = "" ;

    $LLayer = array_merge($Layer, $LLayer);
    make_tag($LLayer, "BuildAttribs", &$Layer_Tag);
    print $Layer_Tag . $endl ;

    return true ;
}

function End_Layer()
{
    global $Layer, $endl ;

    print $Layer['end_tag'] . $endl ;
    return true ;
}

function Start_Frameset($LFrmset)
{
    global $Frameset, $endl ;

    $Frameset_Tag = "" ;

    $LFrameset = array_merge($Frameset, $LFrameset);
    make_tag($LFrameset, "BuildAttribs", &$Frameset_Tag);
    print $Frameset_Tag . $endl ;

    return true ;
}

function End_Frameset()
{
    global $Frameset, $endl ;
    print $Frameset['end_tag'] . $endl ;
    return true;
}

function Draw_Label($LLabel = "")
{
  global $Font, $endl ;
  $LabelTag = "" ;

  if (!is_array($LLabel) )
  {
    print "$LLabel" . $endl ;
    return ;
  } 

  $LLabel = array_merge($Font, $LLabel);

  $LText =  $LLabel["text"] ;

    $LLabel["text"] = "" ;
    make_tag($LLabel, "BuildAttribs", &$LabelTag);
    $LabelTag .= $LText . $Font['end_tag'] ;

  print $LabelTag . $endl ;

}

/** common function for <nolayer>, <noframe>, <noembed>, <noscript>
*   usage: Out_No("Your browser has no support for layers", "layer");
*/

function NoTag($nomsg = "", $tagtype)
{
    global $endl ;
    if ($tagtype == "") { return false ; }

    print "<no$tagtype>"    . $endl ;
    print "$nomsg"          . $endl ;
    print "</no$tagtype>"   . $endl ;

    return true ;
}

function TextTag($Text = "", $tagtype="B")
{
    global $endl ;

    print "<$tagtype>" .   "$Text" . "</$tagtype>" . $endl ;

    return true ;
}

function MkSpace($count = 1)
{
  $Space = "" ;

  for($i=0;$i<$count;$i++)
    $Space .= "&nbsp;" ;

    return $Space ;
}

/*TEST CODE     */

  start_html();
    start_head();
      out_title("list");
      out_base("http://larry.bks/~escms");
    end_head();
  start_body();


$Href =  array('href' => 'listview.php',
               'text' => 'List  View Link'
              );
$Label = array('size' =>'3pt',
               'text' =>'Click Here to see ',
               'color' => 'darkblue'
              );

Draw_Label($Label);


Start_SelectBox(array('name' => 'ddd'));
Draw_SelOptions(array('yah' => 'yahoo.com',  
                      'red' => 'rediff.com',
                      'alt' => 'altavista.com'
                      ),
                      'yah'
                      );
End_SelectBox();

Start_A(array('href' => 'htmldoc.php'),
array('key'=>'value', 'man'=>'woman'));
Draw_Img(array('src' =>'html.gif', 'alt' => 'HTML  Documentation'));
End_A();
Draw_Button(array('type' => "image", "name" => "merapyar", "src" => 'pyari.gif'));
NoTag("This Browser has no support for Script", "script");
NoTag("This Browser has no support for Frames", "frame");

TextTag("This is BOLD Text",   "B");
TextTag("This is STRONG Text",   "STRONG");
TextTag("This is Italic Text",   "ITALIC");
TextTag("This is Underlined Text",   "UL");
TextTag("This is Subscript Text",   "SUB");
TextTag("This is Superscript Text",   "SUP");


 end_body();
end_html();

?>

This is Documentation for functions in htmlwriter.php
------------------------------------------------------

HTML Writer 1.0
Author: S.Murali Krishnan <smk_bk@yahoo.com>

    Though there exists many HTML Writers in many sites the reason Iam
presenting same stuff is two things. When I use such HTML
writers I have to go through the code to understand its working and also
if I want to extend them, I have to understand and track the code
to find suitable place to add anything.


    This documentation not only describes, usage of htmlwriter but also
the working of the same. This documentation seems to be too Technical
way, anyway better documentaion could be made if this is not sufficient.

If you find this documentaion awkward, mail to me any queries regarding
the code and usage, I will try my possible to solve any problems.

E-Mail: smk_bk@yahoo.com

Let me present a test code using this library of functions so that
further reading may not be necessary for most of the users unless they
want to know the working of the code.

See the EXTENDING HTML WRITER below to add new functions.

/*-------- Test code ------------*/

  start_html();
    start_head();
      out_title("list");
      out_base("http://larry.bks/~escms");
    end_head();
  start_body();


$Href =  array('href' => 'listview.php',
               'text' => 'List  View Link'
              );
$Label = array('size' =>'3pt',
               'text' =>'Click Here to see ' ,
               'color' => 'darkblue'
              );

Draw_Label($Label);


Start_SelectBox(array('name' => 'ddd'));

Draw_SelOptions(array('yah' => 'yahoo.com',  
                      'red' => 'rediff.com',
                      'alt' => 'altavista.com'
                      ),
                      'yah'
                      );
End_SelectBox();

Start_A(array('href' => 'htmldoc.php'),
        
array('key'=>'value','man'=>'woman'));

Draw_Img(array('src' =>'html.gif','alt' => 'HTML  Documentation'));
End_A();
Draw_Button(array('type' => "image",
                  "name" => "merapyar",
                  "src" => 'pyari.gif'
                  ));

NoTag("This Browser has no support for Script","script");
NoTag("This Browser has no support for Frames","frame");

TextTag("This is Bold Text",        "B");
TextTag("This is superscript Text", "SUP");
TextTag("This is Subscript Text",   "SUB");
TextTag("This is ITALIC Text",      "I");
TextTag("This is STRONG Text",      "STRONG");
TextTag("This is Underlined Text",  "UL");

Out_Tag("<table color='blue'>");  // accept string or array
Out_Tag(array('start_tag' =>  "<newtag>",
              'end_tag'   =>  "</newtag>" ,
              'color'     => 'blue'
              )
       );

 end_body();
end_html();


/*---------------------- END TEST CODE ----------------------------*/


Documentation 
-------------

  "htmlwriter.inc"  includes functions necessary for drawing html tags
and form element tags.

  This documentation describes the way in which HTML tags were builded and
printed.

Attributes  Data Structure
--------------------------

  For every HTML Tag there would be one or more attributes. If we are
designing similar pages, most of this attributes remains same for each 
occurance of every particular tag.

  The data struture for storing tag attibutes using php associative array is
as follows.

  $Tagname = array(
                   'start_tag'  => '<Tagname>',
                   'end_tag'    => '</Tagname>',
                   'attribute1' => 'value1',
                   'attribute2' => 'value2',
                   'attribute3' => 'value3'
                   'others'     => ''
                   .............
                   .....
                   ....
                  )

  For example Structure for TABLE tag would be as follows.

  $Table  = array (
                    'start_tag'   => '<table>', 
                   'end_tag'     => '</table>'
                   'color'       => 'darkred',
                   'bgcolor'     => 'white',
                   'cellpadding' => '0',
                   'cellspacing' => '0',
                   'border'      => '1',
                   'others'      => ''
                   ...
                   ....
                );
  
  In the above structure for Table tag,
  
  'start_tag'     key defines the starting tag for TABLE tag.
  'end_tag'     key defines the ending closing tag for the TABLE tag.
  
  All the other keys, form each attribute for <TABLE> tag. 
  'others'      this key would be normally empty, but
                this could be used in two situations.
               
              1.  In some tags the attribute would be simple string rather 
                than 'key=value' pair.
                
                example: <option  value='xxxx' selected> text </option>
                          <select name='xx' multiple > ... </select>
                          <input type="checkbox" checked>
                          
                In the above tags 'selected' and 'multiple' attributes are 
                simple strings which were not accompanied by any keys.
                
             2. Different tags may have different javascript events 
                 like 'onSubmit' , 'onClick', 'onChange' , 'onSelect' .
                It is unlikely to hardcode all the possible events for
                all the tags in this array.
              
                To overcome this problem this 'others' key is used.
                That is whenever we want to add anything other than
                'key=value' attributes to tags, we can pass those
                string in this 'others' key.
                
                ( It would be more clear when we go through the
                 tag building algorithm ).

    For some attributes like 'bgcolor', 'color', etc the value on the 
    right side would form the default value when the user haven't supplied
    those attribute values. ( because for a particular page mostly this
    attributes are going to be same for all the tags. ). 
  
  Like this we can define for all the Possible or most frequently used
  tags which we are going to use. ( BODY, TABLE, TD, TR, TH, FONT, 
  FORM, SELECT, INPUT, TEXTAREA, LINK, BUTTON, RADIO ).

  lets see another example ( FORM tag )

  $Form   = array (
                    'start_tag' => '<form>',
                    'end_tag'   => '</form>',
                    'action'    => 'http://....',
                    'name'      => 'form_name',
                    'method'    => 'post',
                    'others'    => ''
                  );
                    
    This attribute definition for all the tags would be placed in top
  of all the functions.

Functions and Output
---------------------

    if we want to print a '<table>' tag with few attributes we can call the
function 'Start_Table' as follows.

<?php
$table = array(
                'bgcolor' => '#333122',
                'color'   => '#222212',
                'height'  => '100%',
                'width'   => '50%',
                'border'  => '0'
             );

Start_Table($table);
?>

  After this call 'Start_Table' would Output the following tag.

  "<table cellpadding='0' cellspacing='0' bgcolor='#333122' color='#222212' 
  height='100%'  width='50%' border='0' >"

  For closing the <table> tag we can call the function 'End_Table' 
  which would output the following.

  End_Table();

  "</table>"

Like this we could do for all the possible tags.
Function names are case insensitive in php, we can call all the start
functions by simply prepending 'Start_' to the actual tag, and end functions
by adding 'End_' to the actual tag

function names for calling some of the tags are given below.

  Tagname  |   Start function   |   End Function
  ----------------------------------------------
  TD           Start_Td              End_Td
  TR           Start_Tr             End_Tr
  BODY         Start_Body           End_Body
  SELECT       Start_Select         End_Select
  HTML         Start_Html           End_Html
  A            Start_A              End_A
  .....
  ....
  

Tag Building
-------------
  Algorithm for building attributes and priting the tag is as follows.

Example for Printing  "<TABLE>" Tag is shown below, this steps would be
same for most of the tags. Status of the tag at each step is also shown.

PROCEDURE: Start_Table
Args:   $LTable  ( Associative array of Attributes )
BEGIN:

  Step 1:
    
    global $Table  ;  // Get copy of Already defined TABLE attributes.
    Table_Tag = "" ;  // Make new Empty variable.

    Tag Status : ''

 Step 2:
       Merge the Global attributes and Passed attributes for table.

      $Attrib = array_merge($Table,$LTable);

      While merging,  the order of arguments should be maintained in 
      array_merge, because array_merge would overwrite the key's value
      if the same is found in the second array.

          By merging we would get a new array with following properties.

          1. All the Global attributes for the tag are available.
          2. Any key=value in global Array ( $Table ) would be overwritten
             by the same key in Passed argument Array.

        See the documentation for array_merge for further details
Step 3: 
          Append all the attributes  (key=value  of $Attrib ) to the
          Table Tag.

          Our Requirement is: 
          ------------------
          
          1. If the key is 'end_tag' it should be skipped.
          
          2. If  key is 'others' or 'start_tag' , its value alone should be
          appended to the tag, without key. ( for 'multiple','selected', 
          'checked', <table> )
          
          3. If the value of the attribute is null, then it should be skipped.
          
          4. All other 'key values' should be appended as
          "key='value' " format to the tag. 
          


          For this we will use 'make_tag' on $Attrib as follows.
          ( see below for make_tag procedure )

          make_tag($Attrib,'BuildAttribs','Table_Tag');
          
          Arguments
          ---------
            $Attrib       --  Array of attributes
            BuildAttribs  --  Function name to invoke for each key value pair.
                              ( Procedure for BuildAttrs is explained below )
            Table_Tag     --  Argument to BuildAttribs ( to which attribs are
                              appended )

          make_tag  
          ----------
            
            Applies the user-defined function named by second argument to each element of
            array. BuildAttribs will be passed array value as the first parameter and array
            key as the second parameter. If userdata is supplied, it will be
            passed as the third parameter to the BuildAttribs function. 


            Our $Table_Tag variable should be updated by each call of 
            'BuildAttribs' function so we will pass '$Table_Tag' by
            reference so that all the appended attributes would be available 
            at the end.

           Tag Status : "<table cellpadding='0' cellspacing='0' bgcolor='#333122' color='#222212' height='100%'  width='50%' border='0'>"

Step 4:    
            Print the Table Tag.        

            Tag Status : "<table cellpadding='0' cellspacing='0' bgcolor='#333122' color='#222212' height='100%'  width='50%' border='0' >\n" 
Step 5:
            Return 

END 

END PROCEDURE

  At the end of this steps we builded a <TABLE> Tag with attributes of our
  interest.

  status  of $Table_Tag after each step is shown below.
  -----------------------------------------------------


    Step 1: ""
    Step 2: ""
    Step 3:  ( Inside array_walk )
        $Table_Tag = "<table>" ;
      i) "<table cellpadding='0'>"
     ii) "<table cellpadding='0' cellspacing='0' >"
     ii) "<table cellpadding='0' cellspacing='0' bgcolor='#333122' >"
    iii) "<table cellpadding='0' cellspacing='0' bgcolor='#333122' color='#222212' >"
     iv) "<table cellpadding='0' cellspacing='0' bgcolor='#333122' color='#222212' height='100%' >"
      v) "<table cellpadding='0' cellspacing='0' bgcolor='#333122' color='#222212' height='100%'  width='50%' >"
     vi) "<table cellpadding='0' cellspacing='0' bgcolor='#333122' color='#222212' height='100%'  width='50%' border='0' " 
    
    Step 4: "<table cellpadding='0' cellspacing='0' bgcolor='#333122' color='#222212' height='100%'  width='50%' border='0' >"
    Step 5: "<table cellpadding='0' cellspacing='0' bgcolor='#333122' color='#222212' height='100%'  width='50%' border='0' >\n"

  
Make_Tag
---------

  The main function in building tag is Make_Tag.
  This function build the tag by appending attributes to the tag.
  since the third argument is passed by reference its value would
  be retained outside of this function (ie . in Start_Table also )

PROCEDURE: Make_Tag
     Args: $Attr, "BuildAttribs" , $Tag_Var
            $Attr          - array of attributes to the tag.
           "BuildAttribs" - function to build each attribute.
           "Tag_Var"      - The Tag string which attributes to be appended.
BEGIN:
  1. Append value of 'start_tag' key of $Tag_Var 
  2. Unset 'start_tag' element of array, so that it would not be
     visible in further attributes.
  3. append all the 'key=value' of $Attrib as attribute to the tag.
      for each $attr in $Attrib
          build attrib
          append attrib
      endfor
  4. return tag.
END 
END PROCEDURE
  
BuildAttribs
------------
  This is the function invoked by array_walk in Tag building functions.
This function will get a key , value and a variable as arguments.
Procedure for this function is shown below.

PROCEDURE: BuildAttribs 
     Args: key, value , Tag_variable
     (Tag_Variable is by reference so any change to Tag_Variable would be
      visible in the calling function )
BEGIN:
  IF value != "" 
  begin:
    
    IF key == 'end_tag'
     RETURN 
    ELSE IF key == 'others' 
      attrib  = value
      insert attrib before close angle bracket ( substr_replace) of Tag_Variable
    ELSE
      attrib = key + "=" + "'value'" 
      insert attrib before close angle bracket of Tag_Variable
    ENDIF
  end
  return Tag_Variable
  ENDIF
END

Tag Closing Function
--------------------

Any 'Start_' type function also has its corresponding 'End_' function.
For our Start_Table function there is a corresponding End_Table function,
in which we would print "</table>" tag.

Procedure for End_Table Function is as follows.
--------------------------------------------------

PROCEDURE: End_Table
     Args: Nothing
BEGIN:
   Get copy of $Table array.
  print value of 'end_tag' key in $Table
  print "\n" 
END


PHP code for these three functions ( Start_Table, End_Table, BuildAttribs )
is shown below.
-------------------------------------------------------------------------------

function End_Table()
{
  global $endl,$Table ;
  print $Table["end_tag"] . $endl ; // print </table>
  return ;
}

Generic Tag Printing function
-----------------------------

In case we want to print a new tag that is not defined before, we can use the
function Out_Tag to print that.
  This Out_Tag doesn't refer any global variable for merging as in start_table
it only build the attributes with the passed array. This requires that 
we have to pass start_tag and end_tag too.

for example building <img> tag we have to call the function in the
following way.

<?php
$img = array(
              'start_tag' => '<img>', 
              'src'       => 'cool.jpg',
              'border'    => '0',
              'height'    => 200,
              'width'     => 100
            );
  Out_Tag($img);
?>

  This above code would output the following.

  <img src='cool.jpg' border='0' height='200' width='100'>
  
  We can also call Out_Tag to output a string of tag as follows.
  
 Out_Tag("<body color='#212111' bgcolor='#291929'>");

EXTENDING HTML WRITER
---------------------
    If you want to add any new HTML Tag functions, simply define the
necessary tag array at the start of this file, then define two functions as
follows.

    function Start_TAGNAME ($Tagarray) {
        global $TAGARRAY
        .....
        See other function definitions for what to do here.
    }

    function End_TAGNAME () {
        ....
    }

    Then call the functions as others.

    Start_Tagname(array(....));
    End_Tagname();

TODO
----
*    Tags array can be placed in a seperate file called "tags.inc"
*    In each tag array "end_tag" key is not necessary if we do apply
     some logic to make_tag() function.
*    Instead of declaring each function for every tag, a workaround has
     to be done using OOPs to minimize no. of functions


     Probably you may expect all these things in next release.

     Mail to me if any new TODOs needs to be done.
     
-------------------------------------------------------------------------------