i retrieve contents of website domdoc , query elements xpath. example query <p>
elements - doing inside loop $paragraphs = $dom->query('//p')->item(i);
, continue manipulate <p>
inside loop. now, there way find out kind of other html elements maybe inside <p>
, how many other elements inside paragraph element?
i have seen example : php documentation
but seems work if know child elements? how can count , element name if "contents" of <p></p>
is unknown me.
thank you!
well, on dom element have can use getelementsbytagname('*')
find descendant elements or can use xpath relative element find child element path *
or count them xpath expression count(*)
or can same descendant elements using .//*
respectively count(.//*)
.
so given $element = $dom->query('//p')->item(i);
can use $element->getelementsbytagname('*')->length
dom way find descendants, or $dom->query('.//*', $element)
xpath way. child elements use $dom->query('*', $element)
.
Comments
Post a Comment