我正在通過DOMDocument類向每個鏈接添加#b哈希。php DOMDocument增加了<html>標題DOCTYPE聲明
$dom = new DOMDocument();
$dom->loadHTML($output);
$a_tags = $dom->getElementsByTagName('a');
foreach($a_tags as $a)
{
$value = $a->getAttribute('href');
$a->setAttribute('href', $value . '#b');
}
return $dom->saveHTML();
這工作正常,但返回的輸出包括DOCTYPE
聲明和一個<head>
和<body>
標籤。任何想法爲什麼發生這種情況,或者我可以如何防止這種情況?
可能重複[PHP + DOM文檔:?outerHTML的元素(http://stackoverflow.com/questions/5404941/php-domdocument-externalhtml-for-element) – hakre 2013-07-03 05:00:40