2013-05-07 60 views

回答

0

我有一个功能,我用它来得到任何给定元素的innerHTML:

function InnerHtml($element) 
{ 
    $innerHTML = ""; 
    if($element != NULL && $element->hasChildNodes()) 
    { 
     $children = $element->childNodes; 
     foreach ($children as $child) 
     { 
      $tmp_dom = new DOMDocument(); 
      $tmp_dom->appendChild($tmp_dom->importNode($child, true)); 
      $innerHTML.=trim($tmp_dom->saveHTML()); 
     } 
    } 
    return $innerHTML; 
} 

如果查询表

$dom_document = new DOMDocument(); 
@$dom_document->loadHTML("Your Page - However you have decided to download it"); 
$table = $dom_document->query("table[class='MyList]'"); 

然后,您应该能够只是通过最后一个在列表中:

enter code here echo InnerHtml($ table-> item(count($ table)-1));

我还没有测试过,但它基本上是你的后。