Zend - The PHP Company




HTML

Add Code


liststr.php - html lists in php  

Type: code fragment
Added by: homechicken
Entered: 12/01/2001
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 4940
A modified version of lists.php, this one returns strings instead of printing html. It is related to htmlstr.php, formstr.php, and tablestr.php. It can be included with any/all related files, but if included along with lists.php, remember the function names are postfixed with a "_str". See example for details


<?
    
/* liststr.php
     *
     * functions for creating html lists
     *
     * Refer HTML questions to http://www.w3.org/TR/REC-html40/
     *
     * Returns string instead of printing output.  Contains no formatting.
     */

    
if(defined("USING_LISTS")) {
        
        function 
ul_str($args="") {
            
$temp "<UL";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
            
/* possible $args: class */
        
}

        function 
ul_close_str() {
            return(
"</UL>");
        }

        function 
ol_str($args="") {
            
$temp "<OL";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
            
/* possible $args: class */
        
}

        function 
ol_close_str() {
            return(
"</OL>");
        }

        function 
li_str($text=""$args="") {
            
$temp "<LI";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            if(
$text != "")
                
$temp .= "$text</LI>";
            return(
$temp);
            
/* possible $args: value */
        
}

        function 
li_close_str() {
            return(
"</LI>");
            
/* not necessary, but here for compatibility and/or compliance */
        
}

    } else {

        function 
ul($args="") {
            
$temp "<UL";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
            
/* possible $args: class */
        
}

        function 
ul_close() {
            return(
"</UL>");
        }

        function 
ol($args="") {
            
$temp "<OL";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
            
/* possible $args: class */
        
}

        function 
ol_close() {
            return(
"</OL>");
        }

        function 
li($text=""$args="") {
            
$temp "<LI";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            if(
$text != "")
                
$temp .= "$text</LI>";
            return(
$temp);
            
/* possible $args: value */
        
}

        function 
li_close() {
            return(
"</LI>");
            
/* not necessary, but here for compatibility and/or compliance */
        
}
    }
?>    



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