Posted By

smoover on 09/04/09


Tagged

html strip tags text plaintext


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

umang_nine
ignace


HTML to Text


 / Published in: PHP
 

  1. function html2txt($text)
  2. {
  3. $search = array(
  4. '@<script[^>]*?>.*?</script>@si', // Strip out javascript
  5. '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
  6. '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
  7. '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
  8. );
  9. $text = preg_replace($search, '', $text);
  10. return $text;
  11. }

Report this snippet  

You need to login to post a comment.