Changeset f50cc72 in github
- Timestamp:
- Dec 12, 2008 3:02:33 AM (5 years ago)
- Branches:
- master, HEAD, courier-fix, dev-browser-capabilities, pdo, release-0.6, release-0.7, release-0.8
- Children:
- 2b5c123
- Parents:
- 8f79fba
- File:
-
- 1 edited
-
program/lib/html2text.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
program/lib/html2text.php
r300fc65 rf50cc72 150 150 '/<style[^>]*>.*?<\/style>/i', // <style>s -- which strip_tags supposedly has problems with 151 151 //'/<!-- .* -->/', // Comments -- which strip_tags might have problem a with 152 '/<h[123][^>]*>(.*?)<\/h[123]>/ie', // H1 - H3153 '/<h[456][^>]*>(.*?)<\/h[456]>/ie', // H4 - H6154 152 '/<p[^>]*>/i', // <P> 155 153 '/<br[^>]*>/i', // <br> 156 '/<b[^>]*>(.*?)<\/b>/ie', // <b>157 '/<strong[^>]*>(.*?)<\/strong>/ie', // <strong>158 154 '/<i[^>]*>(.*?)<\/i>/i', // <i> 159 155 '/<em[^>]*>(.*?)<\/em>/i', // <em> … … 162 158 '/<li[^>]*>(.*?)<\/li>/i', // <li> and </li> 163 159 '/<li[^>]*>/i', // <li> 164 '/<a [^>]*href=("|\')([^"\']+)\1[^>]*>(.*?)<\/a>/ie',165 // <a href="">166 160 '/<hr[^>]*>/i', // <hr> 167 161 '/(<table[^>]*>|<\/table>)/i', // <table> and </table> 168 162 '/(<tr[^>]*>|<\/tr>)/i', // <tr> and </tr> 169 163 '/<td[^>]*>(.*?)<\/td>/i', // <td> and </td> 170 '/<th[^>]*>(.*?)<\/th>/ie', // <th> and </th>171 164 '/&(nbsp|#160);/i', // Non-breaking space 172 165 '/&(quot|rdquo|ldquo|#8220|#8221|#147|#148);/i', … … 202 195 '', // <style>s -- which strip_tags supposedly has problems with 203 196 //'', // Comments -- which strip_tags might have problem a with 204 "strtoupper(\"\n\n\\1\n\n\")", // H1 - H3205 "ucwords(\"\n\n\\1\n\")", // H4 - H6206 197 "\n\n", // <P> 207 198 "\n", // <br> 208 'strtoupper("\\1")', // <b>209 'strtoupper("\\1")', // <strong>210 199 '_\\1_', // <i> 211 200 '_\\1_', // <em> … … 214 203 "\t* \\1\n", // <li> and </li> 215 204 "\n\t* ", // <li> 216 '$this->_build_link_list("\\2", "\\3")',217 // <a href="">218 205 "\n-------------------------\n", // <hr> 219 206 "\n\n", // <table> and </table> 220 207 "\n", // <tr> and </tr> 221 208 "\t\t\\1\n", // <td> and </td> 222 "strtoupper(\"\t\t\\1\n\")", // <th> and </th>223 209 ' ', // Non-breaking space 224 210 '"', // Double quotes … … 239 225 ); 240 226 227 /** 228 * List of preg* regular expression patterns to search for 229 * and replace using callback function. 230 * 231 * @var array $callback_search 232 * @access public 233 */ 234 var $callback_search = array( 235 '/<(h)[123456][^>]*>(.*?)<\/h[123456]>/i', // H1 - H3 236 '/<(b)[^>]*>(.*?)<\/b>/i', // <b> 237 '/<(strong)[^>]*>(.*?)<\/strong>/i', // <strong> 238 '/<(a) [^>]*href=("|\')([^"\']+)\2[^>]*>(.*?)<\/a>/i', 239 // <a href=""> 240 '/<(th)[^>]*>(.*?)<\/th>/i', // <th> and </th> 241 ); 242 241 243 /** 242 244 * List of preg* regular expression patterns to search for in PRE body, … … 472 474 // Run our defined search-and-replace 473 475 $text = preg_replace($this->search, $this->replace, $text); 476 $text = preg_replace_callback($this->callback_search, array('html2text', '_preg_callback'), $text); 474 477 475 478 // Strip any other HTML tags … … 550 553 } 551 554 } 555 556 /** 557 * Callback function for preg_replace_callback use. 558 * 559 * @param array PREG matches 560 * @return string 561 * @access private 562 */ 563 function _preg_callback($matches) 564 { 565 switch($matches[1]) 566 { 567 case 'b': 568 case 'strong': 569 return $this->_strtoupper($matches[2]); 570 case 'hr': 571 return $this->_strtoupper("\t\t". $matches[2] ."\n"); 572 case 'h': 573 return $this->_strtoupper("\n\n". $matches[2] ."\n\n"); 574 case 'a': 575 return $this->_build_link_list($matches[3], $matches[4]); 576 } 577 } 578 579 /** 580 * Strtoupper multibyte wrapper function 581 * 582 * @param string 583 * @return string 584 * @access private 585 */ 586 function _strtoupper($str) 587 { 588 if (function_exists('mb_strtoupper')) 589 return mb_strtoupper($str); 590 else 591 return strtoupper($str); 592 } 552 593 } 553 594
Note: See TracChangeset
for help on using the changeset viewer.
