Hello.

Explain to me why the find () does not want to work in domDocument'e? I try to do this:

// создаю новый объект класса $dom = new DOMDocument('1.0', 'UTF-8'); // получаю контент @$dom->loadHTML($my_html); // убираю пробелы $dom->preserveWhiteSpace = false; // извлекаю все теги ссылок $links = $dom->getElementsByTagName('table')->find('a'); 

Error output

Call to undefined method DOMNodeList :: find ()

  • And why did you even think that the DOMNodeList::find method exists? Of the documentation of such a method does not know - Dmitriy Simushev

1 answer 1

PHP correctly informs you that the DOMNodeList class DOMNodeList not have a find method.

If you want to receive all the links that are in the tables, then you can use a special XPath query. For example:

 $dom = new DOMDocument('1.0', 'UTF-8'); $dom->loadHTML($my_html); $xpath = new DOMXpath($dom); $links = $xpath->query('*/table//a'); 

And here is a working example on IDE One.

  • For some reason, nothing is displayed. I do not have xml code format, but html . - J. Doe
  • There are really no errors. - J. Doe
  • The code that I gave in the response works. Added proof in the answer. Most likely problems with your markup. There is a feeling that it is not valid. Well, in your question there is an evil symbol @ , which you should never use in PHP. - Dmitriy Simushev