HTML
|
|
|
|
<?php // This function is not meant to be called by user function HTML_MKPARAM_ARR ($string, $delimiter = ",") {
$buf = explode($delimiter, $string);
for ($i=0; $i<count($buf); $i++) {
$buf2 = explode ("=", $buf[$i]);
$result[$buf2[0]] = $buf2[1];
}
unset ($buf);
unset ($buf2);
return $result;
}
// This function is not meant to be called by user function HTML_MKPARAM_STR ($array) {
while (list($key,$val) = each($array)) {
if ($key) {
$result .= " " . strtolower($key);
}
if ($val != "") {
$result .= "="" . $val . """;
}
}
return $result;
}
// This function is not meant to be called by user function HTML_TAG ($tagclass, $params = "", $content = "", $closenow=false) {
print "<" . strtoupper($tagclass);
if (is_string($params)) {
$params = HTML_MKPARAM_ARR($params);
}
if (is_array($params)) {
print HTML_MKPARAM_STR ($params);
}
print ">" . $content;
if ($closenow == true) {
print "</" . strtoupper($tagclass) . ">";
}
}
class CTagDocument {
var $_current = -1;
var $open_tags = array();
function OpenTag ($tagclass, $params = "", $content = "", $closenow=false) {
HTML_TAG($tagclass, $params, $content, $closenow);
if ($closenow == false) {
$this->_current++;
$this->open_tags[$this->_current] = strtoupper($tagclass);
}
}
function CloseTag () {
if ($this->_current > -1) {
print "</" . $this->open_tags[$this->_current] . ">n";
$this->_current--;
}
}
function CloseAllTags() {
while ($this->_current > -1) {
$this->CloseTag();
}
}
function _ident () {
return "CTagDocument/1.1";
}
}
class CHTMLDocument extends CTagDocument {
var $DocType = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
function CHTMLDocument ($title="", $bodyparams=""){
print $this->DocType . "rnrn";
$this->OpenTag ("html");
$this->OpenTag ("head");
$this->OpenTag ("title", "", $title, true);
$this->OpenTag ("meta", "name=generator,content=CHTMLDocument by G. Bauman");
$this->_current--;
$this->CloseTag ();
$this->OpenTag ("body", $bodyparams);
}
function _ident () {
return "CHTMLDocument/1.1";
}
}
?> ?>
|
|
|
Usage Example
|
// To generate a table:
$obj = new CTagDocument;
$obj -> OpenTag ("TABLE","width=100%,bgcolor=silver");
$obj -> OpenTag ("TR");
$obj -> OpenTag ("TD", array("bgcolor"=>"white"), "Cool Stuff!", true);
// notice that you can either pass in an
// associative array or comma-delimited
// list of tag parameters to OpenTag.
$obj -> OpenTag ("TD", "", "yeah!", true);
$obj -> OpenTag ("TD","bgcolor=aqua");
echo "And another column...";
$obj -> CloseAllTags ();
|
|
|
Rate This Script
|
|
|
|