Cotta1000
Cotta1000

Reputation: 111

PHP: Getting child elements from each HTML list entry

I'm using PHP to search through a HTML source file to gather list (li) elements, and I need to get multiple anchor links from within each list entry (i.e. each list entry has a bunch of information including links). I had been using DOMXPath and "query" to get the list elements; but then I need to run the result through another query but of course the result is in the wrong format. Here are the relevant sections of code (with the rest left out for brevity and replaced with "..."):

$xpath = new DomXPath($doc);
....
// first get all (UL) lists of class "mw-contributions-list"
$ULList = $xpath->query("//ul[@class='mw-contributions-list']");
// then loop thru these
for ($UL = 0; $UL < $ULList->length; $UL++) 
{
    //get all (li) elements (they don't have a class)
    $LIList = $ULList->item($UL)->getElementsByTagName("li");
    // then loop thru these LI elements
    for ($LI = 0; $LI < $LIList->length; $LI++) 
    {
        ....
        (at this point I need to do an XPath query on $LIList->item($LI) 
        but after converting it to the correct format.  
        How do I do that? )
        ....
    }
}

Upvotes: 0

Views: 57

Answers (0)

Related Questions