天天看点

php domdocument getelementbyid,在PHP中,使用DomDocument getElementByID不起作用?我究竟做错了什么?...

好的,所以你的解决方案.

对于DIV:

This is not working!

这样做:

$dom = new DOMDocument("1.0", "utf-8");

$dom->loadHTMLFile('YourFile.html');

$div = $dom->getElementById('divID');

echo $div->textContent;

$div->setAttribute("name", "yesItWorks");

?>

只要你传递一个精心制作的XML或XHTML内容,就可以在没有文件的情况下工作

$dom->loadHTMLFile('YourFile.html');

到你的

$dom->loadHTML($html);

哦是的,当然,改变内容(完整性):

$div->removeChild($div->firstChild);

$newText = new DOMText('Yes this works!');

$div->appendChild($newText);

然后你可以再次回声它或什么的.