php简单html dom解析器不更新多个类

php简单html dom解析器不更新多个类,php,simple-html-dom,css,Php,Simple Html Dom,Css,我尝试将两个类应用于如下元素: $div->setAttribute('class', 'txt found'); 不幸的是,它无法工作,因为我将获得以下标记: <div found="" class="txt"> 我还尝试了$div->class=“txt-found”具有相同的结果 有什么办法解决这个问题吗?你能试试下面的方法吗 $div->className = "txt found"; 更新: <?php $divHtml = "<div&g

我尝试将两个类应用于如下元素:

$div->setAttribute('class', 'txt found');
不幸的是,它无法工作,因为我将获得以下标记:

<div found="" class="txt">

我还尝试了
$div->class=“txt-found”具有相同的结果


有什么办法解决这个问题吗?

你能试试下面的方法吗

$div->className = "txt found";
更新:

<?php
$divHtml = "<div></div>";
$dom = new DOMDocument();
$dom->loadHTML($divHtml);
$allElements = $dom->getElementsByTagName('div');
$divElement = $allElements->item(0);
$divElement->setAttribute("class", "txt found");
echo $dom->saveHTML();
?>


我试图复制您的案例,最后它成功了。您可以测试它。如果您发送更多代码,我们可以修改它以便工作

已经尝试过了-导致:如果可以重命名属性(classname->class),这将是一个解决方法…我想这是解析器中的一个错误。。如果不对包含空格的属性使用引号,则会发生这种情况。。解析器设置如下属性:这导致find=”“我已经更新了代码,您能试试吗?如果您发送了更多代码,我们可以修改它