note 26995 deleted from function.strip-tags by ezyang

From: Date: Tue, 05 Aug 2008 16:20:51 +0000
Subject: note 26995 deleted from function.strip-tags by ezyang
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-143169@lists.php.net to get a copy of this message
Note Submitter: dontknowwhat at thehellIamdoing dot com ---- Here's a quickie that will strip out only specific tags. I'm using it to clean up Frontpage and WORD code from included third-party code (which shouldn't have the all the extra header information in it). $contents = "Your HTML string"; // Part 1 // This array is for single tags and their closing counterparts $tags_to_strip = Array("html","body","meta","link","head"); foreach ($tags_to_strip as $tag) { $contents = preg_replace("/<\/?" . $tag . "(.|\s)*?>/","",$contents); } // Part 2 // This array is for stripping opening and closing tags AND what's in between $tags_and_content_to_strip = Array("title"); foreach ($tags_and_content_to_strip as $tag) { $contents = preg_replace("/<" . $tag . ">(.|\s)*?<\/" . $tag . ">/","",$contents); }

« previous php.notes (#143169) next »