Advertisement
fabi0

Untitled

Oct 5th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.63 KB | None | 0 0
  1. function html2txt($text) {
  2.     $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
  3.         '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
  4.         '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
  5.         '@<![\s\S]*?--[ \t\n\r]*>@'         // Strip multi-line comments including CDATA
  6.     );
  7.     $replace_array = array(';', '|#|', '{#}', "{}", "'", "\\", '#');
  8.     $text = trim($text);
  9.     $text = preg_replace($search, '', $text);
  10.     $text = str_replace($replace_array, "", $text);
  11.     $text = htmlspecialchars($text, ENT_COMPAT, 'UTF-8');
  12.     $text = strip_tags($text);
  13.     return $text;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement