removing html attributes by preg_replace
| From: | Tomas Lehuta | Date: | Mon, 17 Feb 2003 13:44:52 +0000 |
| Subject: | removing html attributes by preg_replace | ||
| Groups: | php.general php.lang | ||
| Request: | Send a blank email to php-lang+get-460@lists.php.net to get a copy of this message | ||
hello!
could somebody please help me to build a regexp to strip some attributes
from html code?
i'd like to remove all class="" attributes from html, but the example below
seems not match
i don't know what i'm doing wrong, this simply doesn't work!
<?php
$html = '<A href="http://www.anywhere.com"
class="link"></A>';
echo "input:<br>".htmlspecialchars($html)."<hr>";
$html = preg_replace("|(<\w+[^>]*) +class=\"?.*\"?([^>]*)|iU", \\1\\2,
$html);
echo "output:<br>".htmlspecialchars($html)."<hr>";
?>
input:
<A href="http://www.anywhere.com"
class="link"></A>
output:
<A href="http://www.anywhere.com""link"></A>
why this always removes 'class=' only???
thanx for any help
-lharp-
_________________
aurius media studio
http://www.aurius.sk