note 68757 modified in function.strip-tags by danbrown

From: Date: Sun, 17 May 2009 15:59:22 +0000
Subject: note 68757 modified in function.strip-tags by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154732@lists.php.net to get a copy of this message
<?php 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; } ?> This function turns HTML into text... strips tags, comments spanning multiple lines including CDATA, and anything else that gets in it's way. It's a frankenstein function I made from bits picked up on my travels through the web, thanks to the many who have unwittingly contributed! --was-- <? 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; } ?> This function turns HTML into text... strips tags, comments spanning multiple lines including CDATA, and anything else that gets in it's way. It's a frankenstein function I made from bits picked up on my travels through the web, thanks to the many who have unwittingly contributed! http://php.net/manual/en/function.strip-tags.php

« previous php.notes (#154732) next »