I'm adding a #b hash to each link via the DOMDocument class.
$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();
That works fine, however the returned output includes a DOCTYPE
declaration and a <head>
and <body>
tag. Any idea why that happens or how I can prevent that?