HTML
|
|
|
|
<?
/* html.php
*
* standard functions to create html tags
*
* Refer HTML questions to http://www.w3.org/TR/REC-html40/
*/
/* let other includes know we're here.. */
define("USING_HTML", "Yup");
/* DOCTYPE declaration areas, HTML 4.0 compliant */
function doctype_strict() {
print("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"n");
print("t"http://www.w3.org/TR/REC-html40/strict.dtd">nn");
}
function doctype_transitional() {
print("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"n");
print("t"http://www.w3.org/TR/REC-html40/loose.dtd">nn");
}
function doctype_frameset() {
print("<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN"n");
print("t"http://www.w3.org/TR/REC-html40/frameset.dtd">nn");
}
/* Beginning HTML header functions */
function html() {
print("<HTML>n");
}
function head() {
print("<HEAD>n");
}
function title($title) {
print("t<TITLE>$title</TITLE>n");
}
function meta($attribute, $value) {
print("t<META name="$attribute" content="$value">n");
/* possible $attributes: keywords, author, copyright, date */
}
function meta_http_equiv($attribute, $value) {
print("t<META http-equiv="$attribute" content="$value">n");
/* possible $attributes: refresh($value: "n, url"), Content-Type, Expires */
}
function meta_refresh($seconds, $url) {
print("t<META http-equiv="refresh" content="$seconds, url=$url">n");
/* I use this often enough to make it a function of its own */
}
function link_stylesheet($url) {
print("t<LINK rel="stylesheet" type="text/css" href="$url">n");
}
function head_close() {
print("</HEAD>nn");
}
/* BODY section */
function body($args="") {
$temp = "<BODY";
if($args != "")
$temp .= " $args";
$temp .= ">nn";
print($temp);
}
function div($id, $class) {
print("<DIV id="$id" class="$class">n");
}
function span($class, $text="") {
$temp = "<SPAN class="$class">";
if($text != "")
$temp .= "$text</SPAN>";
$temp .= "n";
print($temp);
}
function span_close() {
print("</SPAN>n");
}
function div_close() {
print("</DIV>n");
}
function h($num, $text, $align="", $args="") {
$temp = "<H$num";
if($align != "")
$temp .= " align="$align"";
if($args != "")
$temp .= " $args";
$temp .= ">$text</H$num>n";
print($temp);
/* possible $args: id, class, title, style, and intrinsic events (onclick, etc.) */
}
function address($args="") {
$temp = "<ADDRESS";
if($args != "")
$temp .= " $args";
$temp .= ">n";
print($temp);
/* possible $args: id, class, lang, intrinsic events */
}
function address_close() {
print("</ADDRESS>n");
}
function sub($text) {
print("<SUB>$text</SUB>");
}
function sup($text) {
print("<SUP>$text</SUP>");
}
function p($align="", $args="") {
$temp = "<P";
if($align != "")
$temp .= " align="$align"";
if($args != "")
$temp .= " $args";
$temp .= ">";
print($temp);
/* possible $args: id, class, lang, title, style, intrinsic events */
}
function p_close() {
print("</P>n");
/* not very necessary, but sometimes useful */
}
function br($num=1, $args="") {
if($args=="") {
for($i=0; $i<$num; $i++)
print("<BR>n");
}
else
print("<BR $args>n");
/* possible $args: id, class, title, style, clear */
}
function pre($text) {
print("n<PRE>n$textn</PRE>n");
/* preformatted text */
}
function a($url, $text="", $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 = "<A href="$url"";
if($args != "")
$temp .= " $args";
$temp .= ">$text</A>";
print($temp);
/* some $args: title, style, type, charset, intrinsic events */
}
function anchor($name, $text) {
print("<A name="$name">$text</A>");
}
function img($src, $border=0, $alt="", $height=0, $width=0) {
$temp = "n<IMG src="$src" border=$border";
if($alt != "")
$temp .= " alt="$alt"";
if($height != 0)
$temp .= " height=$height";
if($width != 0)
$temp .= " width=$width";
$temp .= ">n";
print($temp);
}
function img_link($url, $src, $alt="", $border=0, $height=0, $width=0) {
$temp = "n<A href="$url"><IMG src="$src"";
if($alt != "")
$temp .= " alt="$alt"";
$temp .= " border=$border";
if($height != 0)
$temp .= " height=$height";
if($width != 0)
$temp .= " width=$width";
$temp .= "></A>n";
print($temp);
}
function hr($args="") {
$temp = "<HR";
if($args != "")
$temp .= " $args";
$temp .= ">n";
print($temp);
}
function comment($text) {
print("nt<!-- $text -->n");
}
function body_close() {
print("n</BODY>n</HTML>");
}
function center($text="") {
$temp = "<CENTER>";
if($text != "")
$temp .= "$text</CENTER>";
$temp .= "n";
print($temp);
}
function center_close() {
print("n</CENTER>n");
}
function b($text="") {
$temp = "<B>";
if($text != "")
$temp .= "$text</B>";
print($temp);
}
function i($text="") {
$temp = "<I>";
if($text != "")
$temp .= "$text</I>";
print($temp);
}
function b_close() {
print("</B>");
}
function i_close() {
print("</I>");
} ?>
|
|
|
Usage Example
|
<? include("html.php"); doctype_transitional(); html(); head(); title("This is my title"); link_stylesheet("../index.css"); meta("Author", "Jacob Cord"); head_close(); body(bgcolor="white"); h(1, "center", "This is centered H1"); p();
print("This is the first paragraph."); br(2); /* 2 line breaks */ img("foo.png", 0, "This is foo.png"); body_close(); ?>
I will post more examples as soon as my new site is up. Sorry for the delays.
|
|
|
Rate This Script
|
|
|
|