Thanks to Joss Sanglier (http://www.dancingbear.co.uk/) for adding
several more HTML entity codes to the $search and $replace arrays.
Updated 11/7/03.
Thanks to Darius Kasperavicius (http://www.dar.dar.lt/) for
suggesting the addition of $allowed_tags and its supporting function
(which I slightly modified). Updated 3/12/04.
Thanks to Justin Dearing for pointing out that a replacement for the
tag was missing, and suggesting an appropriate fix.
Updated 8/25/04.
Thanks to Mathieu Collas (http://www.myefarm.com/) for finding a
display/formatting bug in the _build_link_list() function: email
readers would show the left bracket and number ("[1") as part of the
rendered email address.
Updated 12/16/04.
Thanks to Wojciech Bajon (http://histeria.pl/) for submitting code
to handle relative links, which I hadn't considered. I modified his
code a bit to handle normal HTTP links and MAILTO links. Also for
suggesting three additional HTML entity codes to search for.
Updated 03/02/05.
Thanks to Jacob Chandler for pointing out another link condition
for the _build_link_list() function: "https".
Updated 04/06/05.
Thanks to Marc Bertrand (http://www.dresdensky.com/) for
suggesting a revision to the word wrapping functionality; if you
specify a $width of 0 or less, word wrapping will be ignored.
Updated 11/02/06.
*** Big housecleaning updates below:
Thanks to Colin Brown (http://www.sparkdriver.co.uk/) for
suggesting the fix to handle and blank lines (whitespace).
Christian Basedau (http://www.movetheweb.de/) also suggested the
blank lines fix.
Special thanks to Marcus Bointon (http://www.synchromedia.co.uk/),
Christian Basedau, Norbert Laposa (http://ln5.co.uk/),
Bas van de Weijer, and Marijn van Butselaar
for pointing out my glaring error in the
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
@param bool $from_file Indicates $source is a file to pull content from
$from_file
search_replace_cb_H1toH3()
search_replace_cb_H1toH3(string $text) : string
search_replace_cb_H1toH3 function.
Parameters
string
$text
Returns
string
—
convert
search_replace_cb_H4toH6()
search_replace_cb_H4toH6(string $text) : string
search_replace_cb_H4toH6 function.
Parameters
string
$text
Returns
string
—
convert
search_replace_cb_B()
search_replace_cb_B(string $text) : string
search_replace_cb_B function.
Parameters
string
$text
Returns
string
—
convert
search_replace_cb_STRONG()
search_replace_cb_STRONG(string $text) : string
search_replace_cb_STRONG function.
Parameters
string
$text
Returns
string
—
convert
search_replace_cb_A_HREF()
search_replace_cb_A_HREF(string $text) : string
search_replace_cb_A_HREF function.
Parameters
string
$text
Returns
string
—
convert
search_replace_cb_TH()
search_replace_cb_TH(string $text) : string
search_replace_cb_TH function.
Parameters
string
$text
Returns
string
—
convert
set_html()
set_html( $source, boolean $from_file = false)
Loads source HTML into memory, either from $source string or a file.
@param string $source HTML content
Parameters
$source
boolean
$from_file
Indicates $source is a file to pull content from
get_text()
get_text()
Returns the text, converted from HTML.
@return string
print_text()
print_text()
Prints the text, converted from HTML.
p()
p()
Alias to print_text(), operates identically.
@see print_text()
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.
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
$width characters.
_build_link_list()
_build_link_list(string $link, $display)
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
@param string $display Part of the text to associate number with