Properties

$html

$html : 

Contains the HTML content to convert.

Type

$text

$text : 

Contains the converted, formatted text.

Type

$width

$width : 

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

$search

$search : 

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

Type

$replace

$replace : 

List of pattern replacements corresponding to patterns searched.

Type

$ent_search

$ent_search : 

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

Type

$ent_replace

$ent_replace : 

List of pattern replacements corresponding to patterns searched.

Type

$callback_search

$callback_search : 

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

Type

$pre_search

$pre_search : 

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

Type

$pre_replace

$pre_replace : 

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

Type

$pre_content

$pre_content : 

Temporary workspace used during PRE processing.

Type

$allowed_tags

$allowed_tags : 

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

Type

$url

$url : 

Contains the base URL that relative links should resolve to.

Type

$_converted

$_converted : 

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

Type

$_link_list

$_link_list : 

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

Type

$_options

$_options : 

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

Type

Methods

__construct()

__construct(string  $source = '', boolean  $from_file = false, array  $options = array()) 

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 = false) 

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(string  $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

string $allowed_tags

set_base_url()

set_base_url(string  $url = '') 

Sets a base URL to handle relative links.

Parameters

string $url

_convert()

_convert() 

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

_converter()

_converter(string  $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

string $text

Reference to HTML content string

_build_link_list()

_build_link_list(string  $link, string  $display, null  $link_override = null) : 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

null $link_override

Returns

string

_convert_pre()

_convert_pre(string  $text) 

Helper function for PRE body conversion.

Parameters

string $text

HTML content

_convert_blockquotes()

_convert_blockquotes(string  $text) 

Helper function for BLOCKQUOTE body conversion.

Parameters

string $text

HTML content

_preg_callback()

_preg_callback(array  $matches) : string

Callback function for preg_replace_callback use.

Parameters

array $matches

PREG matches

Returns

string

_preg_pre_callback()

_preg_pre_callback(array  $matches) : string

Callback function for preg_replace_callback use in PRE content handler.

Parameters

array $matches

PREG 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