Jump to content
MakeWebGames

Recommended Posts

Posted
<?php
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);
?>

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...