I have to clear all style attributes but not text-align and color from:
<p style="font-size:14px; font-family:Arial; text-aligh:right; color:#f2f2f2;">TEXT</p>
to:
<p style="text-aligh:right; color:#f2f2f2;">TEXT</p>
Looping through the p tags and changing them if the node has font styles.
$content = '<p style="font-size:14px; font-family:Arial; text-align:right; color:#f2f2f2;">TEXT1</p>';
$dom = new DOMDocument;
$dom->loadHTML($content, LIBXML_HTML_NOIMPLIED);
$nodes = $dom->getElementsByTagName('p');
foreach($nodes as $node)
{
if ($node->hasAttribute('style'))
{
$node->setAttribute('style',preg_replace('/font-.*?;\s*/','',$node->getAttribute('style')));
}
}
$content = $dom->saveHTML($dom->documentElement);
echo $content, PHP_EOL;