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 222)

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 74)

construct an HTML A tag with optional parameters and attributes and optional fragment

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>

Note: somehow the parameter $fragment never made it to earlier versions of html_a(). This parameter was added at the end of the parameter list for compatibility reasons (2014-05-13/PF)

  • return: ready to use A tag
string html_a ([string $href = ''], [string|array $params = NULL], [string|array $attributes = NULL], [string $anchor = NULL], [string $fragment = 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
  • string $fragment: the optional position within the targeted page
html_attributes (line 177)

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 200)

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 209)

companion of html_form: close the tag

void html_form_close ()
html_img (line 123)

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 259)

STUB

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

STUB

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

STUB

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

STUB

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

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 304)
void html_table_cell ([ $attributes = NULL], [ $content = NULL])
  • $attributes
  • $content
html_table_cell_close (line 309)
void html_table_cell_close ()
html_table_close (line 289)

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 314)
void html_table_head ([ $attributes = NULL], [ $content = NULL])
  • $attributes
  • $content
html_table_head_close (line 319)
void html_table_head_close ()
html_table_row (line 294)
void html_table_row ([ $attributes = NULL], [ $content = NULL])
  • $attributes
  • $content
html_table_row_close (line 299)
void html_table_row_close ()
html_tag (line 141)

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
html_tag_close (line 155)

companion of html_tag: close the tag

  • return: ready to use HTML close tag
string html_tag_close ([string $tag = ''])
  • string $tag: is the HTML-tag to close, e.g. 'span' or 'script'

Documentation generated on Tue, 28 Jun 2016 19:09:46 +0200 by phpDocumentor 1.4.0