Skip to content

Instantly share code, notes, and snippets.

@round
Created December 8, 2018 04:35
Show Gist options
  • Save round/8e1200262403802227864eb83627c01b to your computer and use it in GitHub Desktop.
Save round/8e1200262403802227864eb83627c01b to your computer and use it in GitHub Desktop.
XPath getElementsByClassName equivalent
$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