|
Moodle
2.2.1
http://www.collinsharper.com
|
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 | |
Definition at line 100 of file html2text.php.
| _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.
| string | $link | URL of the link |
| string | $display | Part of the text to associate number with private |
Definition at line 512 of file html2text.php.

| _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
Definition at line 454 of file html2text.php.


| _convert_pre | ( | &$ | text | ) |
Helper function for PRE body conversion.
| string | $text | HTML content private |
Definition at line 544 of file html2text.php.

| _preg_callback | ( | $ | matches | ) |
Callback function for preg_replace_callback use.
| array | $matches | PREG matches |
Definition at line 565 of file html2text.php.

| _strtoupper | ( | $ | str | ) |
Strtoupper multibyte wrapper function
| string | $str |
Definition at line 600 of file html2text.php.


| get_text | ( | ) |
Returns the text, converted from HTML.
public
Definition at line 372 of file html2text.php.


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().
| string | $source | HTML content |
| boolean | $from_file | Indicates $source is a file to pull content from |
| boolean | $do_links | Indicate whether a table of link URLs is desired |
| integer | $width | Maximum width of the formatted text, 0 for no limit public |
Definition at line 336 of file html2text.php.

| p | ( | ) |
Alias to print_text(), operates identically.
public
Definition at line 399 of file html2text.php.

| print_text | ( | ) |
Prints the text, converted from HTML.
public
Definition at line 387 of file html2text.php.

| 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
Definition at line 412 of file html2text.php.
| set_base_url | ( | $ | url = '' | ) |
Sets a base URL to handle relative links.
public
Definition at line 425 of file html2text.php.

| set_html | ( | $ | source, |
| $ | from_file = false |
||
| ) |
Loads source HTML into memory, either from $source string or a file.
| string | $source | HTML content |
| boolean | $from_file | Indicates $source is a file to pull content from public |
Definition at line 355 of file html2text.php.

| boolean $_converted = false |
Indicates whether content in the $html variable has been converted yet.
private
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
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
Definition at line 311 of file html2text.php.
| string $_link_list = '' |
Contains URL addresses from links to be rendered in plain text.
private
Definition at line 301 of file html2text.php.
| string $allowed_tags = '' |
Contains a list of HTML tags to allow in the resulting text.
public
Definition at line 275 of file html2text.php.
| array $callback_search |
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 |
| array $pre_replace |
array( '<br>', ' ', ' ', '', '' )
List of pattern replacements corresponding to patterns searched for PRE body.
public
Definition at line 260 of file html2text.php.
| array $pre_search |
array( "/\n/", "/\t/", '/ /', '/<pre[^>]*>/', '/<\/pre>/' )
List of preg* regular expression patterns to search for in PRE body, used in conjunction with $pre_replace.
public
Definition at line 245 of file html2text.php.
| array $replace |
List of pattern replacements corresponding to patterns searched.
public
Definition at line 183 of file html2text.php.
List of preg* regular expression patterns to search for, used in conjunction with $replace.
public
Definition at line 138 of file html2text.php.
| string $text |
| 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.