Created
December 8, 2018 04:35
-
-
Save round/8e1200262403802227864eb83627c01b to your computer and use it in GitHub Desktop.
XPath getElementsByClassName equivalent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$xpath = new DOMXpath($dom); | |
$items = array(); | |
$expression = './/div[contains(concat(" ", normalize-space(@class), " "), " class-name ")]'; | |
foreach ($xpath->evaluate($expression) as $div) { | |
$items[] = $div; | |
} | |
echo $items[0]->getAttribute('otherattribute'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment