from a html source, using dom and xpath how would I return an array containing all the div class names? I use the following which returns all the div class names that contain "XX", but don't know the query to use for $targets to return all. I know this should be simple but I can't find one that works.
$doc = new DOMDocument();
$doc->loadHTML($data);
$xpath = new DOMXpath($doc);
$targets = $xpath->query(".//div[contains(@class, 'XX')]");
$classNames_array = array();
foreach ($targets as $target) {
$classNames_array[] = $target->textContent;
}
print_r(array_values($classNames_array));
Thanks.
My Answer:
$html = '
Div 1
Rate this post
3 of 5 based on 4047 votesComments