Zend - The PHP Company




HTML

Add Code


htmlstr.php  

Type: code fragment
Added by: homechicken
Entered: 11/01/2001
Last modified: 01/12/2000
Rating: - (fewer than 3 votes)
Views: 6211
As I promised, though a bit late, here are the same functions out of html.php that return strings. This is related to liststr.php, formstr.php, and tablestr.php. These files can be included with any of the original ones that don't return strings, but note the functions are named with a postfixed "_str".


<?
    
/* htmlstr.php
     *
     * standard functions to create html tags
     *
     * Refer HTML questions to http://www.w3.org/TR/REC-html40/
     * 
     * Returns strings instead of printing html lines.
     *  aside from doctype declarations, this file contains no line formatting like t or n
     */

    
if(defined("USING_HTML")) {
    
        
/* DOCTYPE declarations, HTML 4.0 compliant */

        
function doctype_strict_str() {
            
$temp "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"n";
            
$temp .= "t"http://www.w3.org/TR/REC-html40/strict.dtd">nn";
            
return($temp);
        }

        function 
doctype_transitional_str() {
            
$temp "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"n";
            
$temp .= "t"http://www.w3.org/TR/REC-html40/loose.dtd">nn";
            
return($temp);
        }

        function 
doctype_frameset_str() {
            
$temp "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"n";
            
$temp .= "t"http://www.w3.org/TR/REC-html40/frameset.dtd">nn";
            
return($temp);
        }

    
        
/* Beginning HTML header functions */

        
function html_str() {
            return(
"<HTML>");
        }

        function 
head_str() {
            return(
"<HEAD>");
        }

        function 
title_str($title) {
            return(
"<TITLE>$title</TITLE>");
        }

        function 
meta_str($attribute$value) {
            return(
"<META name="$attribute" content="$value">");
            
/* possible $attributes: keywords, author, copyright, date */
        
}

        function 
meta_http_equiv_str($attribute$value) {
            return(
"t<META http-equiv="$attribute" content="$value">");
            
/* possible $attributes: refresh($value: "n, url"), Content-Type, Expires */
        
}
    
        function 
meta_refresh_str($seconds$url) {
            return(
"<META http-equiv="refresh" content="$secondsurl=$url">");
        }

        function 
link_stylesheet_str($url) {
            return(
"<LINK rel="stylesheet" type="text/css" href="$url">");
        }

        function 
head_close_str() {
            return(
"</HEAD>");
        }
    
        
/* BODY section */
    
        
function body_str($args="") {
            
$temp "<BODY";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
        }

        function 
div_str($id$class) {
            return(
"<DIV id="$id" class="$class">");
        }

        function 
span_str($class$text="") {
            
$temp "<SPAN class="$class">";
            if(
$text != "")
                
$temp .= "$text</SPAN>";
            return(
$temp);
        }

        function 
span_close_str() {
            return(
"</SPAN>");
        }

        function 
div_close_str() {
            return(
"</DIV>");
        }

        function 
h_str($num$text=""$align=""$args="") {
            
$temp "<H$num";
            if(
$align != "")
                
$temp .= " align=$align";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            if(
$text != "")
                
$temp .= "$text</H$num>";
            return(
$temp);
            
/* possible $args: id, class, title, style, and intrinsic events (onclick, etc.) */
        
}
    
        function 
h_close_str($num) {
            return(
"</H$num>");
            
/* Not intended for much use, I recommend passing text to h() instead */
        
}

        function 
address_str($args="") {
            
$temp "<ADDRESS";
            if(
$args != "")
                
$temp .= $args;
            
$temp .= ">";
            return(
$temp);
            
/* possible $args: id, class, lang, intrinsic events */
        
}

        function 
address_close_str() {
            return(
"</ADDRESS>");
        }

        function 
sub_str($text) {
            return(
"<SUB>$text</SUB>");
        }

        function 
sup_str($text) {
            return(
"<SUP>$text</SUP>");
        }

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

        function 
p_close_str() {
            return(
"</P>");
            
/* not very necessary, but sometimes useful */
        
}

        function 
br_str($num=1$args="") {
            
$temp "";
            if(
$args == "") {
                for(
$i=0$i<$num$i++)
                    
$temp .= "<BR>";
            } else
                
$temp "<BR $args>";
            return(
$temp);
            
/* possible $args: id, class, title, style, clear */
        
}

        function 
pre_str($text="") {
            
$temp "<PRE>";
            if(
$text != "")
                
$temp .= "$text</PRE>";
            return(
$temp);
            
/* preformatted text */
        
}
    
        function 
pre_close_str() {
            return(
"</PRE>");
        }
    
        function 
a_str($url$text=""$args="") {
            
$temp "<A href="$url"";
            if(
$args != "")
                
$temp .= $args";
            if(
$text=="") {
                
ereg("^([a-zA-Z]+://)([a-zA-Z0-9.-]+(:[0-9]+)?)(((/[a-zA-Z0-9.-]+)?)+)"$url$match);
                
$text $match[2] . $match[4];
                
/* Who's your daddy?!!
                   $match[0] is entire expression
                   $match[1] is protocol (ftp://, http://, telnet://)
                   $match[2] is name/domain (www.foobar.com)
                   $match[3] is optional port number
                   $match[4] is everything optional afterwards
                   $match[5+] is everything matched inside match[3], know your data!
                   
                   this does a great job with external links, but not relative links.
                   if you use a() make relative links ("../index.html", etc.) make sure
                   you pass a $text argument as well, or else you won't get anything.
                 */
            
}
            
$temp .= ">$text</A>";
            return(
$temp);
            
/* some $args: title, style, type, charset, intrinsic events */
        
}
    
        function 
anchor_str($name$text) {
            return(
"<A name="$name">$text</A>");
        }
    
        function 
img_str($src$border=-1$alt=""$height=0$width=0) {
            
$temp "<IMG src="$src"";
            if(
$border >= 0)
                
$temp .= " border=$border";
            if(
$alt != "")
                
$temp .= " alt="$alt"";
            if(
$height 0)
                
$temp .= " height=$height";
            if(
$width 0)
                
$temp .= " width=$width";
            
$temp .= ">";
            return(
$temp);
        }
    
        function 
img_link_str($url$src$alt=""$border=-1$height=0$width=0) {
            
$temp "<A href="$url"><IMG src="$src"";
            if(
$border >= 0)
                
$temp .= " border=$border";
            if(
$alt != "")
                
$temp .= " alt="$alt"";
            if(
$height 0)
                
$temp .= " height=$height";
            if(
$width 0)
                
$temp .= " width=$width";
            
$temp .= "></A>";
            return(
$temp);
        }
    
        function 
hr_str() {
            return(
"<HR>");
            
/* TODO: check to see if there are args to HR */
        
}
    
        function 
comment_str($text) {
            return(
"<!-- $text -->");
        }
        
        function 
body_close_str() {
            return(
"</BODY></HTML>");
        }
        
        function 
center_str($text="") {
            
$temp "<CENTER>";
            if(
$text != "")
                
$temp .= "$text</CENTER>";
            return(
$temp);
        }
        
        function 
center_close_str() {
            return(
"</CENTER>");
        }
        
        function 
b_str($text="") {
            
$temp "<B>";
            if(
$text != "")
                
$temp .= "$text</B>";
            return(
$temp);
        }
        
        function 
b_close_str() {
            return(
"</B>");
        }
        
        function 
i_str($text="") {
            
$temp "<I>";
            if(
$text != "")
                
$temp .= "$text</I>";
            return(
$temp);
        }
        
        function 
i_close_str() {
            return(
"</I>");
        }
        
    } else {
        
        function 
doctype_strict() {
            
$temp "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"n";
            
$temp .= "t"http://www.w3.org/TR/REC-html40/strict.dtd">nn";
            
return($temp);
        }

        function 
doctype_transitional() {
            
$temp "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"n";
            
$temp .= "t"http://www.w3.org/TR/REC-html40/loose.dtd">nn";
            
return($temp);
        }

        function 
doctype_frameset() {
            
$temp "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"n";
            
$temp .= "t"http://www.w3.org/TR/REC-html40/frameset.dtd">nn";
            
return($temp);
        }
    
        
/* Beginning HTML header functions */

        
function html() {
            return(
"<HTML>");
        }

        function 
head() {
            return(
"<HEAD>");
        }

        function 
title($title) {
            return(
"<TITLE>$title</TITLE>");
        }

        function 
meta($attribute$value) {
            return(
"<META name="$attribute" content="$value">");
            
/* possible $attributes: keywords, author, copyright, date */
        
}

        function 
meta_http_equiv($attribute$value) {
            return(
"t<META http-equiv="$attribute" content="$value">");
            
/* possible $attributes: refresh($value: "n, url"), Content-Type, Expires */
        
}
    
        function 
meta_refresh($seconds$url) {
            return(
"<META http-equiv="refresh" content="$secondsurl=$url">");
        }

        function 
link_stylesheet($url) {
            return(
"<LINK rel="stylesheet" type="text/css" href="$url">");
        }

        function 
head_close() {
            return(
"</HEAD>");
        }
    
        
/* BODY section */

        
function body($args="") {
            
$temp "<BODY";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            return(
$temp);
        }

        function 
div($id$class) {
            return(
"<DIV id="$id" class="$class">");
        }

        function 
span($class$text="") {
            
$temp "<SPAN class="$class">";
            if(
$text != "")
                
$temp .= "$text</SPAN>";
            return(
$temp);
        }

        function 
span_close() {
            return(
"</SPAN>");
        }

        function 
div_close() {
            return(
"</DIV>");
        }

        function 
h($num$text=""$align=""$args="") {
            
$temp "<H$num";
            if(
$align != "")
                
$temp .= " align=$align";
            if(
$args != "")
                
$temp .= $args";
            
$temp .= ">";
            if(
$text != "")
                
$temp .= "$text</H$num>";
            return(
$temp);
            
/* possible $args: id, class, title, style, and intrinsic events (onclick, etc.) */
        
}
    
        function 
h_close($num) {
            return(
"</H$num>");
        }

        function 
address($args="") {
            
$temp "<ADDRESS";
            if(
$args != "")
                
$temp .= $args;
            
$temp .= ">";
            return(
$temp);
            
/* possible $args: id, class, lang, intrinsic events */
        
}

        function 
address_close() {
            return(
"</ADDRESS>");
        }

        function 
sub($text) {
            return(
"<SUB>$text</SUB>");
        }

        function 
sup($text) {
            return(
"<SUP>$text</SUP>");
        }

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

        function 
p_close() {
            return(
"</P>");
            
/* not very necessary, but sometimes useful */
        
}

        function 
br($num=1$args="") {
            
$temp "";
            if(
$args == "") {
                for(
$i=0$i<$num$i++)
                    
$temp .= "<BR>";
            } else
                
$temp "<BR $args>";
            return(
$temp);
            
/* possible $args: id, class, title, style, clear */
        
}

        function 
pre($text="") {
            
$temp "<PRE>";
            if(
$text != "")
                
$temp .= "$text</PRE>";
            return(
$temp);
            
/* preformatted text */
        
}
    
        function 
pre_close() {
            return(
"</PRE>");
        }

        function 
a($url$text=""$args="") {
            
$temp "<A href="$url"";
            if(
$args != "")
                
$temp .= $args";
            if(
$text=="") {
                
ereg("^([a-zA-Z]+://)([a-zA-Z0-9.-]+(:[0-9]+)?)(((/[a-zA-Z0-9.-]+)?)+)"$url$match);
                
$text $match[2] . $match[4];
                
/* Who's your daddy?!!
                   $match[0] is entire expression
                   $match[1] is protocol (ftp://, http://, telnet://)
                   $match[2] is name/domain (www.foobar.com)
                   $match[3] is optional port number
                   $match[4] is everything optional afterwards
                   $match[5+] is everything matched inside match[3], know your data!
                   
                   this does a great job with external links, but not relative links.
                   if you use a() make relative links ("../index.html", etc.) make sure
                   you pass a $text argument as well, or else you won't get anything.
                 */
            
}
            
$temp .= ">$text</A>";
            return(
$temp);
            
/* some $args: title, style, type, charset, intrinsic events */
        
}

        function 
anchor($name$text) {
            return(
"<A name="$name">$text</A>");
        }

        function 
img($src$border=-1$alt=""$height=0$width=0) {
            
$temp "<IMG src="$src"";
            if(
$border >= 0)
                
$temp .= " border=$border";
            if(
$alt != "")
                
$temp .= " alt="$alt"";
            if(
$height 0)
                
$temp .= " height=$height";
            if(
$width 0)
                
$temp .= " width=$width";
            
$temp .= ">";
            return(
$temp);
        }

        function 
img_link($url$src$alt=""$border=-1$height=0$width=0) {
            
$temp "<A href="$url"><IMG src="$src"";
            if(
$border >= 0)
                
$temp .= " border=$border";
            if(
$alt != "")
                
$temp .= " alt="$alt"";
            if(
$height 0)
                
$temp .= " height=$height";
            if(
$width 0)
                
$temp .= " width=$width";
            
$temp .= "></A>";
            return(
$temp);
        }

        function 
hr() {
            return(
"<HR>");
        }

        function 
comment($text) {
            return(
"<!-- $text -->");
        }
    
        function 
body_close() {
            return(
"</BODY></HTML>");
        }
    
        function 
center($text="") {
            
$temp "<CENTER>";
            if(
$text != "")
                
$temp .= "$text</CENTER>";
            return(
$temp);
        }
    
        function 
center_close() {
            return(
"</CENTER>");
        }
    
        function 
b($text="") {
            
$temp "<B>";
            if(
$text != "")
                
$temp .= "$text</B>";
            return(
$temp);
        }
    
        function 
b_close() {
            return(
"</B>");
        }
    
        function 
i($text="") {
            
$temp "<I>";
            if(
$text != "")
                
$temp .= "$text</I>";
            return(
$temp);
        }
    
        function 
i_close() {
            return(
"</I>");
        }
    }
?>


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