我正在使用 PHP 的 DomDocument 类来解析 HTML。
当我给它带有锚点的 html 并要求它找到所有锚点并将它们存储在一个数组中时,它给了我一个空数组,就好像没有锚点一样。
为什么会这样,我该如何解决?
这是代码:
$dom = new DOMDocument();
$domObject->loadHTML($content);
$anchors = $domObject->getElementsByTagName('a');
print_r($anchors); // returns empty array.
$content 看起来像这样:
<p>
Friend David, I do not think we shall need a call bell as Hello! can be heard 10 to 20 feet away. What you think? Edison - P.S. first cost of sender & receiver to manufacture is only $7.00.[12] Hello, hello! New York, hello!
</p>
<a href="http://the-irf.com/hello/hello5.html">Prev</a>
<a href="hello7.html">Next</a>
<a href="end.html">End</a>
</body>
</html>