📜  php dom 向元素添加类 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:50.988000             🧑  作者: Mango

代码示例1
$dom = new DOMDocument;
$dom->loadHTML($html);
$divs = $dom->getElementsByTagName('div');
foreach ($divs as $div) {
        $div->setAttribute('class', $div->getAttribute('class').' myclass');
}
$html = $dom->saveHTML();