Try this
$html = <<<_HTML
<!DOCTYPE html>
<html>
<head><title>Test</title></head>
<body>
<a href="#">foo</a>bar is dummy string<p>hello</p>
</body>
</html>
_HTML;
$doc = new DOMDocument();
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$textNodes = $xpath->query('/html/body/a/following-sibling::text()[1]');
if ($textNodes->length) {
$node = $textNodes->item(0);
$node->parentNode->removeChild($node);
}
echo '<pre>', htmlspecialchars($doc->saveHTML()), '</pre>';
Result is
<!DOCTYPE html>
<html><head><title>Test</title></head><body>
<a href="#">foo</a><p>hello</p>
</body></html>
Demo here - http://codepad.viper-7.com/akDqkj