File/program/lib/htmllib.php

Description

/program/lib/htmllib.php - useful functions for generating HTML-code

This file provides various utility routines that aid in creating HTML-code.

Functions
href (line 204)

construct a href from a path, params and a fragment

  • todo: should we merge this with html_a() and/or rename this routine to html_href()?
void href (string $path, [array|string $params = ''], [string $fragment = ''])
  • string $path: the hypertext reference
  • array|string $params: the parameter(s) to add to the $path
  • string $fragment: the optional position within the page
html_a (line 69)

construct an HTML A tag with optional parameters and attributes

this constructs an A tag of the form

<a href="$href?p1=v1&p2=v2 att1="val1" att2="val2">

If no parameters are specified, nothing is added to the href. If no attributes are specified the tag only has the href attribute If $params is an array, the elements of this array are added to the href after a rawurlencode(). The complete $href is then escaped via htmlspecialchars(). If $attributes is an array, all elements are added as escaped key-value-pairs. If string, then just append. If $anchor is not empty, the string is appended to the constructed opening tag and subsequently a closing tag is appended.

Note that urlencoding and specialchars are applied to the URL property and that the other properties are only are htmlspecialchars()'ed. The optional $anchor is not changed in any way.

Examples:

html_a('index.php'): <a href="index.php">
html_a('index.php',array('foo'=>'bar')): <a href="index.php?foo=bar">
html_a('index.php',array('x'=>'y'),array('title'=>'foo')): <a href="index.php?x=y" title="foo">
html_a('index.php','',array('class'=>'dimmed'),'baz'): <a href="index.php" class="dimmed">baz</a>
html_a('','',array('name'=>'chapter1'),'chapter 1'): <a name="chapter1">chapter 1</a>

  • return: ready to use A tag
string html_a ([string $href = ''], [string|array $params = NULL], [string|array $attributes = NULL], [string $anchor = NULL])
  • string $href: holds the hypertext reference
  • string|array $params: holds the parameters to add to the $href
  • string|array $attributes: holds the attributes to add to the tag
  • string $anchor: if not empty this string and a closing tag are appended
html_attributes (line 159)

convert an array of name-value pairs to a string

this converts an array of name-value-pairs to a string containing attribute="content" items, where both 'attribute' and 'content' are properly escaped (with htmlspecialchars()). Properties that don't have content, such as 'disabled' or 'selected' or 'checked' can be specified using the special value NULL, e.g. array('disabled' => NULL). If the parameter $attributes happens to be a string, it is returned with a space prepended. If it is neither a string nor an array (e.g. NULL), an empty string is returned. Note that the attribute="content" elements are delimited with spaces, and that a leading space is prepended (but not trailing space is added).

  • return: properly escaped and spaced HTML string with name="value" etc.
string html_attributes (mixed $attributes)
  • mixed $attributes: an array or string with attributes or NULL
html_form (line 182)

construct the opening of a HTML form

string html_form (string $action, [string $method = 'post'], [string|array $attributes = ''])
  • string $action: the url to submit to
  • string $method: either get or post (default)
  • string|array $attributes: holds the attributes to add to the tag
html_form_close (line 191)

companion of html_form: close the tag

void html_form_close ()
html_img (line 115)

construct an HTML IMG tag with optional attributes

this constructs an IMG tag of the form

If no attributes are specified the tag only has the src attribute If $attributes is an array, all elements are added as raw encoded key-value-pairs. If it is a string, then just append.

Examples:

html_img('icon.gif'): <img src="icon.gif">
html_img('icon.gif',array('width'=>16, 'height'=>16)): <img src="icon.gif" width="16" height="16">

  • return: ready to use IMG tag
string html_img ([string $src = ''], [string|array $attributes = NULL])
  • string $src: holds the url to the image file
  • string|array $attributes: holds the attributes to add to the tag
html_input_radio (line 241)

STUB

void html_input_radio ( $name,  $options)
  • $name
  • $options
html_input_select (line 231)

STUB

void html_input_select ( $name,  $options)
  • $name
  • $options
html_input_submit (line 250)

STUB

void html_input_submit ( $name,  $value)
  • $name
  • $value
html_input_text (line 225)

STUB

void html_input_text ( $name)
  • $name
html_table (line 261)

construct the opening of a HTML table

  • return: ready-to-user HTML-code
string html_table ([string|array $attributes = NULL], [ $content = NULL], string $m)
  • string|array $attributes: holds the attributes to add to the tag
  • string $m: margin for improved code readability
  • $content
html_table_cell (line 286)
void html_table_cell ([ $attributes = NULL], [ $content = NULL])
  • $attributes
  • $content
html_table_cell_close (line 291)
void html_table_cell_close ()
html_table_close (line 271)

construct table closing tag

  • return: ready-to-user HTML-code
string html_table_close ([string $m = margin for improved code readability])
  • string $m: margin for improved code readability
html_table_head (line 296)
void html_table_head ([ $attributes = NULL], [ $content = NULL])
  • $attributes
  • $content
html_table_head_close (line 301)
void html_table_head_close ()
html_table_row (line 276)
void html_table_row ([ $attributes = NULL], [ $content = NULL])
  • $attributes
  • $content
html_table_row_close (line 281)
void html_table_row_close ()
html_tag (line 133)

construct a generic HTML-tag with attributes, optionally close it too

  • return: ready to use HTML-tag
string html_tag ([string $tag = ''], [mixed $attributes = NULL], [mixed $content = NULL])
  • string $tag: is the HTML-tag to create, e.g. 'span' or 'script'
  • mixed $attributes: holds the attributes to add to the tag or NULL
  • mixed $content: if not NULL this string and a closing tag are appended

Documentation generated on Wed, 11 May 2011 23:45:13 +0200 by phpDocumentor 1.4.0