HosipLan

Untitled

Mar 11th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.60 KB | None | 0 0
  1. public function texyToText(\Texy $texy)
  2. {
  3.     $html = $texy->getDOM()->toHtml($texy);
  4.     $s = TexyUtf::utf2html($html, $texy->encoding);
  5.  
  6.     // remove tags
  7.     $s = preg_replace('#<(script|style)(.*)</\\1>#Uis', '', $s);
  8.     $s = str_replace('#><#', '> <', $s); // supply spaces
  9.     $s = strip_tags($s);
  10.     $s = preg_replace('#\n\s*\n\s*\n[\n\s]*\n#', "\n\n", $s);
  11.     $s = preg_replace('#\s\s+#', " ", $s);
  12.  
  13.     // entities -> chars
  14.     $s = self::unescapeHtml($s);
  15.  
  16.     // convert nbsp to normal space and remove shy
  17.     $s = strtr($s, array(
  18.         "\xC2\xAD" => '',  // shy
  19.         "\xC2\xA0" => ' ', // nbsp
  20.     ));
  21.  
  22.     return $s;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment