Properties

$html

$html : string

Contains the HTML content to convert.

Type

string

$text

$text : string

Contains the converted, formatted text.

Type

string

$width

$width : integer

Maximum width of the formatted text, in columns.

Set this value to 0 (or less) to ignore word wrapping and not constrain text to a fixed-width column.

Type

integer

$search

$search : array

List of preg* regular expression patterns to search for, used in conjunction with $replace.

Type

array

$replace

$replace : array

List of pattern replacements corresponding to patterns searched.

Type

array

$ent_search

$ent_search : array

List of preg* regular expression patterns to search for, used in conjunction with $ent_replace.

Type

array

$ent_replace

$ent_replace : array

List of pattern replacements corresponding to patterns searched.

Type

array

$callback_search

$callback_search : array

List of preg* regular expression patterns to search for and replace using callback function.

Type

array

$pre_search

$pre_search : array

List of preg* regular expression patterns to search for in PRE body, used in conjunction with $pre_replace.

Type

array

$pre_replace

$pre_replace : array

List of pattern replacements corresponding to patterns searched for PRE body.

Type

array

$allowed_tags

$allowed_tags : string

Contains a list of HTML tags to allow in the resulting text.

Type

string

$url

$url : string

Contains the base URL that relative links should resolve to.

Type

string

$_converted

$_converted : boolean

Indicates whether content in the $html variable has been converted yet.

Type

boolean

$_link_list

$_link_list : array

Contains URL addresses from links to be rendered in plain text.

Type

array

$_options

$_options : array

Various configuration options (able to be set in the constructor)

Type

array

Methods

__construct()

__construct(string $source, boolean $from_file, array $options)

Constructor.

If the HTML source string (or file) is supplied, the class will instantiate with that source propagated, all that has to be done it to call get_text().

Parameters

string $source

HTML content

boolean $from_file

Indicates $source is a file to pull content from

array $options

Set configuration options

set_html()

set_html(string $source, boolean $from_file)

Loads source HTML into memory, either from $source string or a file.

Parameters

string $source

HTML content

boolean $from_file

Indicates $source is a file to pull content from

get_text()

get_text() : string

Returns the text, converted from HTML.

Returns

string

print_text()

print_text()

Prints the text, converted from HTML.

p()

p()

Alias to print_text(), operates identically.

set_allowed_tags()

set_allowed_tags( $allowed_tags)

Sets the allowed HTML tags to pass through to the resulting text.

Tags should be in the form "

", with no corresponding closing tag.

Parameters

$allowed_tags

set_base_url()

set_base_url( $url)

Sets a base URL to handle relative links.

Parameters

$url

_convert()

_convert()

Workhorse function that does actual conversion (calls _converter() method).

_converter()

_converter( $text)

Workhorse function that does actual conversion.

First performs custom tag replacement specified by $search and $replace arrays. Then strips any remaining HTML tags, reduces whitespace and newlines to a readable format, and word wraps the text to $this->_options['width'] characters.

Parameters

$text

_build_link_list()

_build_link_list(string $link, string $display,  $link_override) : string

Helper function called by preg_replace() on link replacement.

Maintains an internal list of links to be displayed at the end of the text, with numeric indices to the original point in the text they appeared. Also makes an effort at identifying and handling absolute and relative links.

Parameters

string $link

URL of the link

string $display

Part of the text to associate number with

$link_override

Returns

string

_convert_pre()

_convert_pre( $text)

Helper function for PRE body conversion.

Parameters

$text

_convert_blockquotes()

_convert_blockquotes( $text)

Helper function for BLOCKQUOTE body conversion.

Parameters

$text

_preg_callback()

_preg_callback( $matches) : string

Callback function for preg_replace_callback use.

Parameters

$matches

Returns

string

_preg_pre_callback()

_preg_pre_callback( $matches) : string

Callback function for preg_replace_callback use in PRE content handler.

Parameters

$matches

Returns

string

_toupper()

_toupper(string $str) : string

Strtoupper function with HTML tags and entities handling.

Parameters

string $str

Text to convert

Returns

string —

Converted text

_strtoupper()

_strtoupper(string $str) : string

Strtoupper multibyte wrapper function with HTML entities handling.

Forces mb_strtoupper-call to UTF-8.

Parameters

string $str

Text to convert

Returns

string —

Converted text