$dom = new DOMDocument; $dom->loadHTML($html); // HTML $xpath = new DOMXPath($dom); // XPath $tags = $xpath->query('//tag'); // foreach ($tags as $tag) { $tag->removeAttribute('attr'); // } // HTML- $new = $dom->saveHTML();
$dom = new DOMDocument; $dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8')); $xpath = new DOMXPath($dom); // del attributes from <table> $tables = $xpath->query('//table'); foreach ($tables as $table) { $table->removeAttribute('width'); $table->removeAttribute('cellspacing'); $table->removeAttribute('cellpadding'); $table->removeAttribute('border'); } // del attr from <tr> $rows = $xpath->query('//tr'); foreach ($rows as $row) { $row->removeAttribute('align'); } $newContent = $dom->saveHTML();
Source: https://habr.com/ru/post/254203/
All Articles