fork download
  1. <?php
  2.  
  3. $html = '<a class="main-img" href="/product/index.jsp">
  4. <img src="14402813t241x292.jpg" height="292" width="241">
  5. </a>';
  6. $doc = new DOMDocument();
  7. libxml_use_internal_errors(true); // just to suppress erros
  8. $doc->loadHTML($html);
  9. $x = new DOMXPath($doc);
  10. $nodes = $x->query("//a[@class='main-img']/img/@src");
  11.  
  12. foreach($nodes as $node){
  13. echo $node->nodeValue. "\n";
  14. }
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
14402813t241x292.jpg