note 85734 added to function.strip-tags

From: Date: Mon, 15 Sep 2008 15:43:09 +0000
Subject: note 85734 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-144422@lists.php.net to get a copy of this message
The following function has a small error: <? function html2txt($document){ $search = array('@<script[^>]*?>.*?</script>@si', // Strip out javascript '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments including CDATA ); $text = preg_replace($search, '', $document); return $text; } ?> It´s a great function and work fine!, but don´t erase the inline <style> code. This function only works 100% fine changing the regexp order to this: <? 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; } ?> ---- Server IP: 130.206.1.5 Probable Submitter: 83.53.41.180 ---- Manual Page -- http://www.php.net/manual/en/function.strip-tags.php Edit -- https://master.php.net/note/edit/85734 Del: integrated -- https://master.php.net/note/delete/85734/integrated Del: useless -- https://master.php.net/note/delete/85734/useless Del: bad code -- https://master.php.net/note/delete/85734/bad+code Del: spam -- https://master.php.net/note/delete/85734/spam Del: non-english -- https://master.php.net/note/delete/85734/non-english Del: in docs -- https://master.php.net/note/delete/85734/in+docs Del: other reasons-- https://master.php.net/note/delete/85734 Reject -- https://master.php.net/note/reject/85734 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144422) next »