0
$some_link = 'http://www.example.com';
$abc = 'killer';
$bcd = 'awsome';
$cde = 'qwerty';
$dom = new DOMDocument;
$dom->preserveWhiteSpace = false;
@$dom->loadHTMLFile($some_link);
$html = getTags($dom, $abc, $bcd, $cde);
echo $html;
function getTags($dom, $abc, $bcd, $cde){
$html = '';
$domxpath = new DOMXPath($dom);
$newDom = new DOMDocument;
$newDom->formatOutput = true;
$defffff = $domxpath->query("//$abc" . '[@' . $bcd . "='$cde']");
// since above returns DomNodeList Object
// converting to string(html)
$i = 0;
while($myItem = $defffff->item($i++)){
$node = $newDom->importNode($myItem, true); // import node
$newDom->appendChild($node); // append node
}
$html = $newDom->saveHTML();
return $html;
}
?>
這是整個代碼。它連續返回多個結果,現在我想要的只是結果no.1和no.5。我該怎麼做?DOM Xpath僅獲得所需結果
我是新來的DOM,嘗試了幾件事情,但沒有成功。由於提前
PERFECT !!!非常感謝你 – koca101
@ koca101歡迎你! –