Moodle  2.2.1
http://www.collinsharper.com
html2text Class Reference

Public Member Functions

 html2text ($source= '', $from_file=false, $do_links=true, $width=75)
 set_html ($source, $from_file=false)
 get_text ()
 print_text ()
 p ()
 set_allowed_tags ($allowed_tags= '')
 set_base_url ($url= '')
 _convert ()
 _build_link_list ($link, $display)
 _convert_pre (&$text)
 _preg_callback ($matches)
 _strtoupper ($str)

Data Fields

 $html
 $text
 $width = 70
 $search
 $replace
 $callback_search
 $pre_search
 $pre_replace
 $allowed_tags = ''
 $url
 $_converted = false
 $_link_list = ''
 $_link_count = 0
 $_do_links = true

Detailed Description

Definition at line 100 of file html2text.php.


Member Function Documentation

_build_link_list ( 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$linkURL of the link
string$displayPart of the text to associate number with private
Returns:
string

Definition at line 512 of file html2text.php.

Here is the caller graph for this function:

_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.

private

Returns:
void

Definition at line 454 of file html2text.php.

Here is the call graph for this function:

Here is the caller graph for this function:

_convert_pre ( &$  text)

Helper function for PRE body conversion.

Parameters:
string$textHTML content private

Definition at line 544 of file html2text.php.

Here is the caller graph for this function:

_preg_callback ( matches)

Callback function for preg_replace_callback use.

Parameters:
array$matchesPREG matches
Returns:
string private

Definition at line 565 of file html2text.php.

Here is the call graph for this function:

_strtoupper ( str)

Strtoupper multibyte wrapper function

Parameters:
string$str
Returns:
string private

Definition at line 600 of file html2text.php.

Here is the call graph for this function:

Here is the caller graph for this function:

get_text ( )

Returns the text, converted from HTML.

public

Returns:
string

Definition at line 372 of file html2text.php.

Here is the call graph for this function:

Here is the caller graph for this function:

html2text ( source = '',
from_file = false,
do_links = true,
width = 75 
)

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$sourceHTML content
boolean$from_fileIndicates $source is a file to pull content from
boolean$do_linksIndicate whether a table of link URLs is desired
integer$widthMaximum width of the formatted text, 0 for no limit public
Returns:
void

Definition at line 336 of file html2text.php.

Here is the call graph for this function:

p ( )

Alias to print_text(), operates identically.

public

Returns:
void
See also:
print_text()

Definition at line 399 of file html2text.php.

Here is the call graph for this function:

Prints the text, converted from HTML.

public

Returns:
void

Definition at line 387 of file html2text.php.

Here is the call graph for this function:

set_allowed_tags ( allowed_tags = '')

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

Tags should be in the form "<p>", with no corresponding closing tag.

public

Returns:
void

Definition at line 412 of file html2text.php.

set_base_url ( url = '')

Sets a base URL to handle relative links.

public

Returns:
void

Definition at line 425 of file html2text.php.

Here is the caller graph for this function:

set_html ( source,
from_file = false 
)

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

Parameters:
string$sourceHTML content
boolean$from_fileIndicates $source is a file to pull content from public
Returns:
void

Definition at line 355 of file html2text.php.

Here is the caller graph for this function:


Field Documentation

boolean $_converted = false

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

private

See also:
$html, $text

Definition at line 292 of file html2text.php.

boolean $_do_links = true

Boolean flag, true if a table of link URLs should be listed after the text.

private

See also:
html2text()

Definition at line 320 of file html2text.php.

integer $_link_count = 0

Number of valid links detected in the text, used for plain text display (rendered similar to footnotes).

private

See also:
_build_link_list()

Definition at line 311 of file html2text.php.

string $_link_list = ''

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

private

See also:
_build_link_list()

Definition at line 301 of file html2text.php.

string $allowed_tags = ''

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

public

See also:
set_allowed_tags()

Definition at line 275 of file html2text.php.

array $callback_search
Initial value:
 array(
        '/<(h)[123456][^>]*>(.*?)<\/h[123456]>/i', 
        '/<(b)[^>]*>(.*?)<\/b>/i',                 
        '/<(strong)[^>]*>(.*?)<\/strong>/i',       
        '/<(a) [^>]*href=("|\')([^"\']+)\2[^>]*>(.*?)<\/a>/i',
                                                   
        '/<(th)[^>]*>(.*?)<\/th>/i',               
        '/<(img)[^>]*alt=\"([^>"]+)\"[^>]*>/i',    
    )

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

public

Definition at line 227 of file html2text.php.

string $html

Contains the HTML content to convert.

public

Definition at line 109 of file html2text.php.

array $pre_replace
Initial value:
 array(
        '<br>',
        '&nbsp;&nbsp;&nbsp;&nbsp;',
        '&nbsp;',
        '',
        ''
    )

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

public

See also:
$pre_search

Definition at line 260 of file html2text.php.

array $pre_search
Initial value:
 array(
        "/\n/",
        "/\t/",
        '/ /',
        '/<pre[^>]*>/',
        '/<\/pre>/'
    )

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

public

See also:
$pre_replace

Definition at line 245 of file html2text.php.

array $replace

List of pattern replacements corresponding to patterns searched.

public

See also:
$search

Definition at line 183 of file html2text.php.

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

public

See also:
$replace

Definition at line 138 of file html2text.php.

string $text

Contains the converted, formatted text.

public

Definition at line 117 of file html2text.php.

string $url

Contains the base URL that relative links should resolve to.

public

Definition at line 283 of file html2text.php.

integer $width = 70

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.

public

Definition at line 128 of file html2text.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations