Justtechjobs.com Find a programming school near you






Online Campus Both


php-general | 2003022

[PHP] removing html attributes by preg_replace From: Tomas Lehuta (lharp <email protected>)
Date: 02/17/03

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

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php