Skip to content
Advertisement

how to get multiple data from xpath query?

This is HTML page (test.html)

JavaScript

The PHP Code here

JavaScript

NOTE: i want to get result like this

JavaScript

Advertisement

Answer

One approach is to use the contextnode parameter to DOMXPath::query to do a subquery on each of the mainid elements for the child subids. Something like this:

JavaScript

Note that the trim calls are necessary or you will end up with all of the whitespace from the original document in your output.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement