diff --git a/lib/html2text.php b/lib/html2text.php new file mode 100644 index 00000000000..f96108f0154 --- /dev/null +++ b/lib/html2text.php @@ -0,0 +1,162 @@ +, +Closing or tags without their corresponding opening tags, +Tags within tags, which will be rendered, even though they +should not be. + +Conversion requires a lot of preg_replace statements, so it can be quite slow with +large HTML files. + +****** +To use +****** + +This library requires PHP 4+ + +To use this library, put the following line in your script before the part that needs it: +require('PATH_TO_THIS_FILE/html2text.php'); + +To convert HTML/PHP to text: + $textVersion = html2text( $HTMLversion ); + +************ +Further info +************ + +For the technically minded, this is the process I use for converting HTML to approx text: + +REMOVE php start and end tags +REMOVE +ensure HTML uses entities in the right places (like inside tags) so strip_tags works properly +' ) + 7 ); $chr = ''; + } elseif( !$is_open_tb && strtolower( substr( $badStr, $x + 1, 6 ) ) == 'script' ) { + $badStr = substr( $badStr, 0, $x ) . substr( $badStr, strpos( strtolower( $badStr ), '' ) + 8 ); $chr = ''; + } elseif( !$is_open_tb ) { $is_open_tb = true; } else { $chr = '<'; } + break; + case '>': + if( !$is_open_tb || $is_open_dq || $is_open_sq ) { $chr = '>'; } else { $is_open_tb = false; } + break; + case '"': + if( $is_open_tb && !$is_open_dq && !$is_open_sq ) { $is_open_dq = true; } + elseif( $is_open_tb && $is_open_dq && !$is_open_sq ) { $is_open_dq = false; } + else { $chr = '"'; } + break; + case "'": + if( $is_open_tb && !$is_open_dq && !$is_open_sq ) { $is_open_sq = true; } + elseif( $is_open_tb && !$is_open_dq && $is_open_sq ) { $is_open_sq = false; } + } $goodStr .= $chr; + } + //now that the page is valid (I hope) for strip_tags, strip all unwanted tags + $goodStr = strip_tags( $goodStr, '