How can I use DOM parser to remove all attributes in span tags but except these two attributes,
<span style="text-decoration: underline;">cultura</span>
accept
<span style="text-decoration: line-through;">heart</span>
accept
reject this,
<span style="font-family: " lang="EN-US">May</span>
accept
Is it possible?
My working code from the other post I made,
$content = '
<span style="text-decoration: underline;">cultura</span>l <span style="text-decoration: line-through;">heart</span>
<span style="font-family: " lang="EN-US">May</span>
';
$dom = new DOMDocument();
$dom->loadHTML($content);
foreach( $dom->getElementsByTagName( "span" ) as $span )
{
foreach( $span->attributes as $attrib )
{
$span->removeAttributeNode( $attrib );
}
}
$content = $dom->saveHTML();
But this code will remove all attributes inside the span
tags...