Created
July 8, 2010 13:39
-
-
Save mattijs/468011 to your computer and use it in GitHub Desktop.
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
function _getElementsByClassName(DOMNode $node, $class) | |
{ | |
$elements = array(); | |
if (XML_ELEMENT_NODE === $node->nodeType && $node->hasAttributes()) { | |
for ($i = 0; $i < $node->attributes->length; $i++) { | |
$attribute = $node->attributes->item($i); | |
if ('class' === strtolower($attribute->name)) { | |
$values = explode(' ', $attribute->value); | |
if (in_array($class, $values)) { | |
$elements[] = $node; | |
} | |
} | |
} | |
} | |
if ($node->hasChildNodes()) { | |
foreach ($node->childNodes as $childNode) { | |
$elements += getElementsByClass($childNode, $class); | |
} | |
} | |
return $elements; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment