function stripLargeTags($html){ $searches = array ( "//si", // Remove CData "/]*?>.*?<\/script>/si", // Strip out javascript "/]*>.*?<\/style>/si", // Strip out styles "/]*>.*?<\/code>/si", // Strip out code chunks "//s", // Strip comments "//Us", // Strip !Tags "/<\?.*>/Us" // Strip !Tags ); $replace = array(); foreach($searches as $search){ array_push($replace, ''); // Replace all with '' } reset($searches); $text = preg_replace($searches, $replace, htmlentities($html)); return html_entity_decode($text); }