php - DOMDocument not working -


i want find images in html string in code below. why results null in example (except node name gives 'img')? want display image html string each image.

 $html = '<img src=\'dasdasdasd.jpg\' >';  $dom = new domdocument(); $dom->loadhtml($html); $els = $dom->getelementsbytagname('img');  foreach ( $els $el ) {     $nodename = strtolower($el->nodename);     $nodetext =  strtolower($el->textcontent);     $nodeval = strtolower($el->nodevalue);         var_dump($nodename);         var_dump($nodetext);         var_dump($nodeval); } 

well, node doesn't have value or text...

what want attribute:

$src = $el->getattribute("src"); var_dump($src); //dasdasdasd.jpg 

as commented, if need whole xml, can use

$xml = $dom->savexml($el); echo $xml; 

Comments