Re: Regular Expressions

From: Date: Mon, 05 Apr 2004 05:22:23 +0000
Subject: Re: Regular Expressions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-182324@lists.php.net to get a copy of this message
* Thus wrote Matt Palermo (webmaster@sweetphp.com): > I have a page where I am stripping the html tags down. Basically, it will > allow certain tags, but still strips out ALL attributs of the tag, so it > works something like this: > > $allowed_tags = "<p><br><strong><b><i><u>"; > // State which tags are allowed > $info = strip_tags($info, $allowed_tags); > // Strip all unwanted tags out > $allowed_tags = "p|br|strong|b|i|u"; > // Convert tags for regular expression > $info = preg_replace("/<(?!".$allowed_tags.")[^>]*>/", > '<\1>', $info); // > Strip out all attributes from allowed tags You might wont to try a look behind assertion: /< (?<=p|br) [^>]+ >/x Curt -- "I used to think I was indecisive, but now I'm not so sure."

« previous php.general (#182324) next »