Flourish PHP Unframework

fHTML

static class, v1.0.0b8

Provides HTML-related methods

This class is implemented to use the UTF-8 character encoding. Please see http://flourishlib.com/docs/UTF-8 for more information.

Changes:
1.0.0b8Changed encode() and prepare() to handle arrays of strings 5/19/10
1.0.0b7Fixed a bug where some conditional comments were causing the regex in prepare() to break 11/4/09
1.0.0b6Updated showChecked() to require strict equality if one parameter is NULL 6/2/09
1.0.0b5Fixed prepare() so it does not encode multi-line HTML comments 5/9/09
1.0.0b4Added methods printOption() and showChecked() that were in fCRUD 5/8/09
1.0.0b3Fixed a bug where makeLinks() would double-link some URLs 1/8/09
1.0.0b2Fixed a bug where makeLinks() would create links out of URLs in HTML tags 12/5/08
1.0.0bThe initial implementation 9/25/07

Static Methods

::containsBlockLevelHTML() public

Checks a string of HTML for block level elements

Signature

boolean containsBlockLevelHTML( string $content )

Parameters

string $content The HTML content to check

Returns

If the content contains a block level tag

::convertNewlines() public

Converts newlines into br tags as long as there aren't any block-level HTML tags present

Signature

void convertNewlines( string $content )

Parameters

string $content The content to display

::decode() public

Converts all HTML entities to normal characters, using UTF-8

Signature

string decode( string $content )

Parameters

string $content The content to decode

Returns

The decoded content

::encode() public

Converts all special characters to entites, using UTF-8.

Signature

string encode( string|array $content )

Parameters

string|array $content The content to encode

Returns

The encoded content

Takes a block of text and converts all URLs into HTML links

Signature

string makeLinks( string $content, integer $link_text_length=0 )

Parameters

string $content The content to parse for links
integer $link_text_length If non-zero, all link text will be truncated to this many characters

Returns

The content with all URLs converted to HTML link

::prepare() public

Prepares content for display in UTF-8 encoded HTML - allows HTML tags

Signature

string prepare( string|array $content )

Parameters

string|array $content The content to prepare

Returns

The encoded html

::printOption() public

Prints an option tag with the provided value, using the selected value to determine if the option should be marked as selected

Signature

void printOption( string $text, string $value, string $selected_value=NULL )

Parameters

string $text The text to display in the option tag
string $value The value for the option
string $selected_value If the value is the same as this, the option will be marked as selected

::sendHeader() public

Sets the proper Content-Type header for a UTF-8 HTML (or pseudo-XHTML) page

Signature

void sendHeader( )

::show() public

Prints a p (or div if the content has block-level HTML) tag with the contents and the class specified - will not print if no content

Signature

boolean show( string $content, string $css_class='' )

Parameters

string $content The content to display
string $css_class The CSS class to apply

Returns

If the content was shown

::showChecked() public

Prints a checked="checked" HTML input attribute if $value equals $checked_value, or if $value is in $checked_value

Please note that if either $value or $checked_value is NULL, a strict comparison will be performed, whereas normally a non-strict comparison is made. Thus 0 and FALSE will cause the checked attribute to be printed, but 0 and NULL will not.

Signature

boolean showChecked( string $value, string|array $checked_value )

Parameters

string $value The value for the current HTML input tag
string|array $checked_value The value (or array of values) that has been checked

Returns

If the checked attribute was printed