Skip to content

Instantly share code, notes, and snippets.

@jameserie
Created May 24, 2011 15:51
Show Gist options
  • Save jameserie/988969 to your computer and use it in GitHub Desktop.
Save jameserie/988969 to your computer and use it in GitHub Desktop.
Convert HTML source to full text
function html2txt($document){
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
'@<[?]php[^>].*?[?]>@si', //scripts php
'@<[?][^>].*?[?]>@si', //scripts php
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA
);$text = preg_replace($search, '', $document);
return $text;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment