note 71962 deleted from function.strip-tags by danbrown
| From: | danbrown@php.net | Date: | Sun, 17 May 2009 15:57:56 +0000 |
| Subject: | note 71962 deleted from function.strip-tags by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-154725@lists.php.net to get a copy of this message | ||
Note Submitter: uersoy at tnn dot net
----
admin at automapit dot com's function is great. Cleans everything I don't need :). But
there is a small problem; strip style tags line should be before strip html tags line. Otherwise,
strip html tags section cleans the <style></style> and between them is stays there as
text.
<?php
function html2txt($document){
$search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript
'@<style[^>]*?>.*?</style>@siU', // Strip style tags
properly
'@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
'@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
including CDATA
);
$text = preg_replace($search, '', $document);
return $text;
}
?>