Possible Duplicate:
DOMDocument::load – PHP – Getting attribute value
I have many div tags pulled from a string through php, each of them having a unique id and a subjective class. I am trying to get the id and class of each of the divs but am not too sure how I would do this.
HTML:
<div id='x1y1' class = 'classname'></div><div id = 'x2y1' class = 'classname1'>
so far I have tried
$html = new DOMDocument();
$html->loadHTML($boardDataStripSlashes);
$elements = $html->getElementsByTagName('div');
but have not been able to find anything on how to get the actual id’s and classes of the selected elements.
You need to use
DOMElement::getAttributeto retrieve attributes of elements.