Zend - The PHP Company




HTML

Add Code


tablestr.php - html tables in php  

Type: code fragment
Added by: homechicken
Entered: 12/01/2001
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 8225
This is the string-returning form of tables.php. It can work together with htmlstr.php, liststr.php, and formstr.php. It can be included with any/all related files, but remember that if included along with tables.php, the function names that return strings are postfixed with a "_str". See example code for details.


<?
    
/* tablestr.php
     *
     * functions to create html tables
     *
     * Refer HTML questions to http://www.w3.org/TR/REC-html40/
     *
     * Returns strings instead of printing output. Contains no formatting.
     */

    
if(defined("USING_TABLES")) {

        function 
table_str($border=0$width=""$spacing=""$padding=""$args="") {
            
$temp "<TABLE border=$border";
            if(
$width != "")
                
$temp .= " width="$width"";
            if(
$spacing != "")
                
$temp .= " cellspacing=$spacing";
            if(
$padding != "")
                
$temp .= " cellpadding=$padding";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
        }

        function 
tr_str($args="") {
            
$temp "<TR";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
            
/* possible tr $args: id, class, lang, title, style, align, char, charoff, valign, intrinsic events */
        
}

        function 
td_str($args="") {
            
$temp "<TD";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
            
/* possible $args: id, class, lang, title, style, bgcolor, align, char, charoff, valign, rowspan, colspan, etc */
        
}

        function 
table_close_str() {
            print(
"</TABLE>");
        }

    } else {

        function 
table($border=0$width=""$spacing=""$padding=""$args="") {
            
$temp "<TABLE border=$border";
            if(
$width != "")
                
$temp .= " width="$width"";
            if(
$spacing != "")
                
$temp .= " cellspacing=$spacing";
            if(
$padding != "")
                
$temp .= " cellpadding=$padding";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
        }

        function 
tr($args="") {
            
$temp "<TR";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
            
/* possible tr $args: id, class, lang, title, style, align, char, charoff, valign, intrinsic events */
        
}

        function 
td($args="") {
            
$temp "<TD";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
            
/* possible $args: id, class, lang, title, style, bgcolor, align, char, charoff, valign, rowspan, colspan, etc */
        
}

        function 
table_close() {
            print(
"</TABLE>");
        }
    }
?>



Usage Example


<?
    
include("includes/html.php");
    include(
"includes/htmlstr.php");
    include(
"includes/tablestr.php");
    include(
"includes/lists.php");
    include(
"includes/liststr.php");
    include(
"includes/formstr.php");
    
doctype_transitional();
    
head();
    
title("This is a test");
    
head_close();
    
body();
    
h(1"Sample Page""center");
    
p();
    print(
"The Tables:");
    print(
table(2"95%"015));
    
printf("%s%srow1cell1n"tr(), td());
    
printf("%srow1cell2n"td());
    
printf("%s%srow2cell1n"tr(), td());
    
printf("%srow2cell2n"td());
    print(
table_close());
    print(
br_str(2));
    print(
"The Lists:");
    
ul();
    
li("Unordered One");
    
printf("%sUnordered Twon"li_str());
    
li();
    print(
"Unordered Three");
    
ul_close();
    
br(2);
    print(
"The Forms:");
    
p();
    
$myform form("process.php");
    for(
$i=0$i<5$i++)
        
$myform .= input_text("field$i"2550) . br_str();
    
$myform .= br_str(1) . center_str();
    
$myform .= input_submit() . input_reset() . center_close_str(). form_close();
    print(
$myform);
    print(
body_close_str());
?>


Rate This Script





Search



This Category All Categories