Version: 0.11

Type: Function

Category: HTML

License: GNU General Public License

Description: Just a simple little function for those who hate going back and forth between html and PHP code.



<?php
/*
 * File:        html.inc.php
 * Written By:  Edwin Robertson {TuxMonkey}
 * Updated By:  David Heaney {superdave}
 * Date:        June 11, 2001
 *
 * I was bored, and I modified the original function to accept a variable
 * number of arguments, instead of one, seperated by semicolons.  It may
 * or may not be an improvement....
 * please let me know if you find any bugs.
 *
 * Syntax: html("element", "attributes", tabs, newline);
 *
 * Note - The only thing actually required is the element
 */

function html($element, $attributes=false, $tabs=0, $newline=false)
{
    // Number of spaces to use for tabs
    $tabstop = 4;

    // Check to see if any tabs are needed
    if($tabs > 0){
        $tab = $tabstop * $tabs;
        for($x = 0;$x < $tab;$x++){
            $spaces .= " ";
        }
    }
    print "$spaces<";
    // Do we need to print a new line at the end
    if($newline == true){
        $new = "\n";
    }
    //
    print $element;
    // Do we have any attributes we need to add
    if($attributes){
        $args = split(" ",$attributes);
        for($x = 0;$x < count($args);$x++){
            $i = split("=",$args[$x]);
            if(strtoupper($i[0]) == "NOWRAP"){
                print " nowrap";
            }
            else if(strtoupper($i[0]) == "SELECTED"){
                print " selected";
            }
            else if(strtoupper($i[0]) == "CHECKED"){
                print " checked";
            }
            else{
                print " $i[0]=\"$i[1]\"";
            }
        }
    }
    // Finish up
    print ">$new";
}

// Example
html("html", "", "", true);
html("head", "", 1, true);
html("title", "", 2);
print "Example";
html("/title", "", 0, true);
html("/head", "", 1, true);
html("body", "bgcolor=white", 1, true);
print "Hello World!\n";
html("/body", "", 1, true);
html("/html", "", 0, true);
?>