fork download
  1. <?php
  2. $html = <<<_HTML
  3. <html>
  4. <body>
  5. <div>
  6. <img src="http://m...content-available-to-author-only...g.com/img/dog_0" orginal="http://m...content-available-to-author-only...g.com/dog_a0" alternate="http://m...content-available-to-author-only...g.com/img/dog_" />
  7. <div>
  8. </body>
  9. </html>
  10. _HTML;
  11.  
  12. $doc = new DOMDocument();
  13. $doc->loadHTML($html);
  14.  
  15. $xpath = new DOMXPath($doc);
  16.  
  17. $images = $xpath->query('//div/img');
  18. foreach ($images as $image) {
  19. foreach ($image->attributes as $attr) {
  20. echo $attr->name, ' = ', $attr->value, PHP_EOL;
  21. }
  22. }
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
src = http://m...content-available-to-author-only...g.com/img/dog_0
orginal = http://m...content-available-to-author-only...g.com/dog_a0
alternate = http://m...content-available-to-author-only...g.com/img/dog_