I am trying to select the images that have no class through my DOMDocument object.
I have the following
$imgParser=new DOMDocument;
@$imgParser->loadHTML($html);
foreach($imgParser->getElementsByTagName('img') as $imgNode){
//the code below will display images with and without class name
echo $imgParser->saveHTML($imgNode);
//I can't user javascript at this point...
//I need to save the images without class into my DB...
//save to DB codes..
}
Are there anyways to do this? Thanks a lot!
You can use
DOMElement::hasAttribute()to determine whether a node has a particular attribute.You can put this at the top of your loop body to skip that node: