Symfony DomCrawler get HTML without attributes / styles

I need a way to get a HTML from an email without attributes (class / styles).

Currently trying the following:

$crawler = new Crawler();
$crawler->addHtmlContent($mail->textHtml);

$html = '';
$nodes = $crawler->filter('body > *'); //only stuff inside body

foreach ($crawler as $domElement) {
    //remove somehow class+styles ?
    $html .= $domElement->ownerDocument->saveHTML($domElement);
}

echo $html; //outputs everything inside body (currently with attributes)

As I read on many questions already, regex is not a good solutions for something like this as it may break stuff.

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *