Skip to content
Advertisement

Return array of all div class names from html source using php

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.

JavaScript

Thanks.

Advertisement

Answer

The query for all classes of divs would be '//div/@class'. Then you get a DomAttr list which you can iterate and get the value as a public property, e.g.

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