HTML_Page2 (Constructor) [line 438]
void HTML_Page2(
[mixed
$attributes = array()])
|
|
Class constructor.
Accepts an array of attributes
General options:
- "lineend" => "unix|win|mac" (Sets line ending style; defaults to
unix.) See also setLineEnd.
- "tab" => string (Sets line ending style; defaults to \t.) See
also setTab.
- "cache" => "false|true" See also setCache.
- "charset" => charset string (Sets charset encoding; defaults
to utf-8) See also setCharset and getCharset.
- "mime" => mime encoding string (Sets document mime type;
defaults to text/html) See also setMimeEncoding.
XHTML specific options:- "doctype" => string (Sets XHTML doctype; defaults to
XHTML 1.0 Transitional.) See also setDoctype.
- "language" => two letter language designation. (Defines global
document language; defaults to "en".) See also setLang.
- "namespace" => string (Sets document namespace; defaults to the
W3C defined namespace.) See also setNamespace.
- "profile" => string (Sets head section profile) See also
setHeadProfile.
- "prolog" => bool (Enables or disables the XML prolog. This is
usually unwanted, as it makes the page invalid XHTML.) See also
disableXmlProlog and enableXmlProlog.
For extensive usage examples, see class-level documentation ({@see HTML_Page2}).
Parameters:
addBodyContent [line 1000]
void addBodyContent(
mixed
$content, [int
$flag = HTML_PAGE2_APPEND])
|
|
Sets the content of the <body> tag
It is possible to add objects, strings or an array of strings and/or objects. Objects must have a toHtml or toString method.
By default, if content already exists, the new content is appended. If you wish to overwrite whatever is in the body, use setBody; unsetBody completely empties the body without inserting new content. You can also use prependBodyContent to prepend content to whatever is currently in the array of body elements.
The following constants are defined to be passed as the flag attribute: HTML_PAGE2_APPEND, HTML_PAGE2_PREPEND and HTML_PAGE2_REPLACE. Their usage should be quite clear from their names.
Parameters:
addFavicon [line 1092]
void addFavicon(
string
$href, [string
$type = 'image/x-icon'], [string
$relation = 'shortcut icon'])
|
|
Adds a shortcut icon (favicon)
This adds a link to the icon shown in the favorites list or on the left of the url in the address bar. Some browsers display it on the tab, as well.
Parameters:
addHeadLink [line 1113]
void addHeadLink(
string
$href, string
$relation, [string
$relType = 'rel'], [array
$attributes = array()])
|
|
Adds <link> tags to the head of the document
$relType defaults to 'rel' as it is the most common relation type used. ('rev' refers to reverse relation, 'rel' indicates normal, forward relation.) Typical tag: <link href="index.php" rel="Start">
Parameters:
addRawHeaderData [line 1827]
void addRawHeaderData(
string
$content)
|
|
Adds raw data to the head of the document
Use this function to add raw data strings to the header.
Parameters:
addScript [line 1023]
void addScript(
string
$url, [string
$type = "text/javascript"])
|
|
Adds a linked script to the page
Parameters:
addScriptDeclaration [line 1040]
void addScriptDeclaration(
mixed
$content, [string
$type = 'text/javascript'])
|
|
Adds a script to the page
Content can be a string or an object with a toString method. Defaults to text/javascript.
Parameters:
addStyleDeclaration [line 1073]
void addStyleDeclaration(
mixed
$content, [string
$type = 'text/css'])
|
|
Adds a stylesheet declaration to the page
Content can be a string or an object with a toString method. Defaults to text/css.
Parameters:
addStyleSheet [line 1055]
void addStyleSheet(
string
$url, [string
$type = 'text/css'], [string
$media = null])
|
|
Adds a linked stylesheet to the page
Parameters:
apiVersion [line 1127]
Returns the current API version
disableXmlProlog [line 1166]
Disables prepending the XML prolog for XHTML documents
Normally, XHTML documents require the XML prolog to be on the first line of each valid document:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
...
However, some browsers, most noticeably Microsoft Internet Explorer, have difficulties properly displaying XHTML in compatibility mode with this. This method is for workaround solutions, such as the infamous CSS Box Hack.
The opposite (and default) effect can be achieved using the enableXmlProlog method.
Usage:
display [line 1793]
Outputs the HTML content to the browser
This method outputs to the default display device. Normally that will be the browser.
If caching is turned off, which is the default case, this generates the appropriate headers:
header("Expires: Tue, 1 Jan 1980 12:00:00 GMT");
header("Last-Modified: " .
gmdate("D, d M Y H:i:s") .
" GMT");
header("Cache-Control: no-cache");
This functionality can be disabled:
enableXmlProlog [line 1188]
Enables prepending the XML prolog for XHTML documents (default)
This method enables the default XHTML output, with an XML prolog on the first line of the document. See disableXmlProlog for more details on why it may or may not be advantageous to have the XML prolog disabled.
Usage:
getBodyContent [line 1838]
Get/Return the Body Content.
getCharset [line 1199]
Returns the document charset encoding.
getDoctypeString [line 1210]
string getDoctypeString(
)
|
|
Returns the document type string
getLang [line 1226]
Returns the document language.
getTitle [line 1237]
Return the title of the page.
prependBodyContent [line 1265]
void prependBodyContent(
mixed
$content)
|
|
Prepends content to the content of the <body> tag. Wrapper for addBodyContent
If you wish to overwrite whatever is in the body, use setBody; addBodyContent provides full functionality including appending; unsetBody completely empties the body without inserting new content. It is possible to add objects, strings or an array of strings and/or objects Objects must have a toString method.
Parameters:
setBody [line 1288]
void setBody(
mixed
$content)
|
|
Sets the content of the <body> tag.
If content exists, it is overwritten. If you wish to use a "safe" version, use addBodyContent. Objects must have a toString method.
This function acts as a wrapper for addBodyContent. If you are using PHP 4.x and would like to pass an object by reference, this is not the function to use. Use addBodyContent with the flag HTML_PAGE2_REPLACE instead.
Parameters:
setBodyAttributes [line 1317]
void setBodyAttributes(
array
$attributes)
|
|
Sets the attributes of the <body> tag
If attributes exist, they are overwritten. In XHTML, all attribute names must be lowercase. As lowercase attributes are legal in SGML, all attributes are automatically lowercased. This also prevents accidentally creating duplicate attributes when attempting to update one.
Parameters:
setCache [line 1337]
void setCache(
[string
$cache = 'false'])
|
|
Defines if the document should be cached by the browser
Defaults to false.
A fully configurable cache header is in the works. for now, though if you would like to determine exactly what caching headers are sent to to the browser, set cache to true, and then output your own headers before calling display.
Parameters:
setCharset [line 1363]
void setCharset(
[string
$type = 'utf-8'])
|
|
Sets the document charset
By default, HTML_Page2 uses UTF-8 encoding. This is properly handled by PHP, but remember to use the htmlentities attribute for charset so that whatever you get from a database is properly handled by the browser.
The current most popular encoding: iso-8859-1. If it is used, htmlentities and htmlspecialchars can be used without any special settings.
Parameters:
setDoctype [line 1385]
void setDoctype(
[string
$type = "XHTML 1.0 Transitional"])
|
|
Sets or alters the !DOCTYPE declaration.
Can be set to "strict", "transitional" or "frameset". Defaults to "XHTML 1.0 Transitional".
This must come after declaring the character encoding with setCharset or directly when the class is initiated HTML_Page2. Use in conjunction with setMimeEncoding
Framesets are not yet implemented.
Parameters:
setHeadProfile [line 1417]
setLang [line 1430]
void setLang(
[string
$lang = "en"])
|
|
Sets the global document language declaration. Default is English.
Parameters:
setMetaContentType [line 1482]
void setMetaContentType(
)
|
|
Sets an http-equiv Content-Type meta tag
setMetaData [line 1445]
void setMetaData(
string
$name, string
$content, [bool
$http_equiv = false])
|
|
Sets or alters a meta tag.
Parameters:
setMetaRefresh [line 1503]
void setMetaRefresh(
int
$time, [string
$url = 'self'], [bool
$https = false])
|
|
Shortcut to set or alter a refresh meta tag
If no $url is passed, "self" is presupposed, and the appropriate URL will be automatically generated. In this case, an optional third boolean parameter enables https redirects to self.
Parameters:
setMimeEncoding [line 1557]
void setMimeEncoding(
[string
$type = 'text/html'])
|
|
Sets the document MIME encoding that is sent to the browser.
This usually will be text/html because most browsers cannot yet accept the proper mime settings for XHTML: application/xhtml+xml and to a lesser extent application/xml and text/xml. See the W3C note (http://www.w3.org/TR/xhtml-media-types/) for more details.
Here is a possible way of automatically including the proper mime type for XHTML 1.0 if the requesting browser supports it:
<?php
// Initialize the HTML_Page2 object:
require 'HTML/Page2.php';
// Check if browse can take the proper mime type
if ( strpos($_SERVER['HTTP_ACCEPT'], 'application/xhtml+xml') ) {
} else {
// HTML that qualifies for XHTML 1.0 Strict automatically
// also complies with XHTML 1.0 Transitional, so if the
// requesting browser doesn't take the necessary mime type
// for XHTML 1.0 Strict, let's give it what it can take.
}
// finish building your page here..
?>
Parameters:
setNamespace [line 1584]
void setNamespace(
[string
$namespace = ''])
|
|
Sets the document namespace
By default, W3C namespaces are used. However, if you need to define your own namespace, you can set it here.
Usage:
// This is how you can set your own namespace:
// This reverts to default setting and retrieves the appropriate
// W3C namespace for the document type:
Parameters:
setTitle [line 1607]
void setTitle(
string
$title)
|
|
Sets the title of the page
Usage:
Parameters:
toFile [line 1748]
void toFile(
string
$filename)
|
|
Generates the document and outputs it to a file.
Uses http://www.php.net/file_put_contents when available. Includes a workaround for older versions of PHP.
Usage example:
<?php
require "HTML/Page2.php";
?>
Parameters:
toHtml [line 1636]
Generates and returns the complete page as a string
This is what you would call if you want to save the page in a database. It creates a complete, valid HTML document, and returns it as a string.
Usage example:
<?php
require "HTML/Page2.php";
// here you insert HTML into a database
?>
unsetBody [line 1299]
Unsets the content of the <body> tag.
unsetMetaData [line 1467]
void unsetMetaData(
string
$name, [bool
$http_equiv = false])
|
|
Unsets a meta tag.
Parameters:
_elementToHtml [line 509]
string _elementToHtml(
&$element, mixed
$element)
|
|
Iterates through an array, returning an HTML string
It also handles objects, calling the toHTML or toString methods and propagating the line endings and tabs for objects that extend HTML_Common.
For more details read the well-documented source.
Parameters: