我想從使用php domddocument的指定網址獲得id ='myid'的完整html表並將其打印到我們的網頁,我該怎麼做?使用php domdocument獲取完整的表格並打印它
我想用下面的代碼來獲取表,但我不能得到trs(錶行)和tds(表數據)和其他內部的html。
$xml = new DOMDocument();
@$xml->loadHTMLFile($url);
foreach($xml->getElementById('myid') as $table)
{
// now how to get tr and td and other element ?
// i am getting other element like :-
$links = $table->getElementsByTagName('a');
foreach($links as $innerAnchor)
{
//doing something with anchor tag...
}
}
需要幫助。
我是新的php domddocument。
非常感謝。
HTML的例子? – ajreal
在調試的時候拿@ off'@ $ xml',那麼至少你會看到錯誤......你一般做的事情看起來是正確的,但對我來說已經很晚了,而且我已經喝了幾杯酒,所以我必須在清晨醒來時更清醒地看... – Endophage
@ajreal,html是從$ xml-> loadHTMLFile函數中傳遞的url給出的,它可以是任何東西將是一個有效的網址。 – Bajrang