我正在使用PHP的DomDocument類來解析HTML。DomDocument_object-> getElementsByTagName('a');返回一個空數組,當頁面上有錨時
當我給它錨定它,並要求它找到所有錨並將它們存儲在一個數組中,它給了我一個空的數組,就好像沒有錨。
爲什麼它這樣做,我該如何解決它?
下面是代碼:
$dom = new DOMDocument();
$domObject->loadHTML($content);
$anchors = $domObject->getElementsByTagName('a');
print_r($anchors); // returns empty array.
和$內容是這樣的:
<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>
你能發佈整個html嗎? – hek2mgl 2013-04-10 23:50:12
@ hek2mgl 這就是$ content中的所有html – 2013-04-11 00:01:20