This class can clear all unwanted HTML/XML attribs.
Download:
http://semlabs.co.uk/assets/files/strip_attributes.zipDemo:
$sa = new StripAttributes();
$sa->allow = array( 'id', 'class' );
$sa->exceptions = array(
'img' => array( 'src', 'alt' ),
'a' => array( 'href', 'title' )
);
$sa->ignore = array();
$str = $sa->strip( $str );
Source:
http://semlabs.co.uk/journal/php-strip-attributes-class-for-xml-and-html