note 96371 added to function.strip-tags

From: Date: Tue, 23 Feb 2010 18:10:26 +0000
Subject: note 96371 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-166294@lists.php.net to get a copy of this message
this is a modified script from admin at automapit dot com back in 2006. I've moved the HTML stripper to the bottom so it will strip out all tags in general (before, it would strip the HTML tags, then skip over the CSS). This way, it processes the code and strips out tags in this order: Javascript, CSS (style), Comments, all other HTML tags. <?php function html2txt($document){ $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<![\s\S]*?--[ \t\n\r]*>@', // Strip multi-line comments including CDATA '@<[\/\!]*?[^<>]*?>@si' // Strip out HTML tags ); $text = preg_replace($search, '', $document); return $text; } ?> all credits go to admin at automapit dot com. just thought I'd point this out. Aside from that, it works beautifully. Keep in mind: If you want to keep the contents of <select> and <option> tags, change the <style> line to "@si" (aka: take out the "U"). Otherwise, these will be treated like HTML tags and be completely taken out. ---- Server IP: 208.69.120.55 Probable Submitter: 216.185.44.209 ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/96371 Del: integrated -- https://master.php.net/note/delete/96371/integrated Del: useless -- https://master.php.net/note/delete/96371/useless Del: bad code -- https://master.php.net/note/delete/96371/bad+code Del: spam -- https://master.php.net/note/delete/96371/spam Del: non-english -- https://master.php.net/note/delete/96371/non-english Del: in docs -- https://master.php.net/note/delete/96371/in+docs Del: other reasons-- https://master.php.net/note/delete/96371 Reject -- https://master.php.net/note/reject/96371 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#166294) next »