Re: Keep HTML tags, but strip attributes

From: Date: Sat, 03 Apr 2004 22:24:01 +0000
Subject: Re: Keep HTML tags, but strip attributes
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-182263@lists.php.net to get a copy of this message
Jochem Maas wrote: ...
regular expressions, heres an example:
a slightly better example, which will display nicely if you try the test in a browser (I think most people start out that way, I know I did.) <? if (isset($_SERVER['HTTP_HOST'])) { ob_start(); } $input = 'this <div>is some</div> <u><b class="haxor">bad</b></u> HTML'; echo "{$input}\n"; $input = preg_replace('/<\/?[^pbiu\/][^>]*>/', '', $input); echo "{$input}\n"; $input = preg_replace('/<([pbiu])[^>]*>/', '<\1>', $input); echo "{$input}\n"; $input = str_replace('bad', 'good', $input); echo "{$input}\n"; if (isset($_SERVER['HTTP_HOST'])) { echo '<pre>'.htmlentities(ob_get_clean()).'</pre>'; } ?> ...

« previous php.general (#182263) next »