PHP methods of striping tags and tag contents

From: Date: Fri, 25 Apr 2003 04:50:16 +0000
Subject: PHP methods of striping tags and tag contents
Groups: php.general 
Request: Send a blank email to php-general+get-145224@lists.php.net to get a copy of this message
What is the most efficient method of removing tags AND the contents between the tags? I took a look at the strip_tags, levenshtein, and ereg_replace commands, but wasn't sure if I was headed in the right directions. I saw some code posted within the man pages for strip_tag: the following code only strips the tag but leaves behind the content that existed between the tags that were removed. <?php function safeHTML($text) { $text = stripslashes($text); $text = strip_tags($text, '<table>'); $text = ereg_replace ("<a[^>]+href *= *([^ ]+)[^>]*>", "<a href=\\1>", $text); $text = ereg_replace ("<([b|i|u])[^>]*>", "<\\1>", $text); return $text; } ?> Initially, I thought I could use levenshtein to discover distances between tags, then use ereg_replace to remove everthing between tags, and, lastly, use strip_tag to get rid of the tags. Any suggestions?

« previous php.general (#145224) next »