note 85734 deleted from function.strip-tags by danbrown

From: Date: Sun, 17 May 2009 15:50:22 +0000
Subject: note 85734 deleted from function.strip-tags by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154702@lists.php.net to get a copy of this message
Note Submitter: valentin -DOT- moreira -AT- atapear.com ---- 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; } ?>

« previous php.notes (#154702) next »