2011-05-16 36 views
3

刪除重複的ID我都需要由DOMDocument::loadHtml($html)解析的HTML,但它給我一個錯誤:整潔 - 如何從HTML

DOMDocument::loadHTML(): ID 'my id' already defined in Entity

我沒有對$html控制,但是我可以使用整潔的lib(或其他東西,想法?)並製作可解析的HTML。 但我沒有在整潔的配置中找到一個選項,以在整潔的配置中刪除重複的ID。我的代碼是這樣的:

$tidy = new tidy(); 
$tidy->parseString($this->getPageContents()); 
$html = new DOMDocument(); 
$html->loadHTML($tidy); // error here 

THX

+0

什麼是$整潔過嗎?一個字符串? – slandau 2011-05-16 20:16:00

+1

一個PHP庫http://php.net/manual/en/book.tidy.php – Lucas 2011-05-17 01:55:32

回答

0

嘗試

$html->loadXML($tidy); 

,比重寫ID的使用XML DOM解析爲HTML DOM

+0

沒有工作,與loadXML引發更多的錯誤 – Lucas 2011-05-17 01:52:02

+0

你可以發佈一個例子$ this-> getPageContents()它是破碎的一個簡單的解決方案 – borrel 2011-05-23 14:18:09