note 26995 added to function.strip-tags

From: Date: Wed, 20 Nov 2002 00:23:22 +0000
Subject: note 26995 added to function.strip-tags
Groups: php.notes 
Request: Send a blank email to php-notes+get-39716@lists.php.net to get a copy of this message
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); } -- http://www.php.net/manual/en/function.strip-tags.php http://master.php.net/manage/user-notes.php?action=edit+26995 http://master.php.net/manage/user-notes.php?action=delete+26995 http://master.php.net/manage/user-notes.php?action=reject+26995

« previous php.notes (#39716) next »