Created
August 16, 2019 13:55
-
-
Save lonalore/5a806e3e67a7cbf31690107d1f034192 to your computer and use it in GitHub Desktop.
PHP: get image src attribute (dom)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$doc = new DOMDocument(); | |
$doc->loadHTML($html); | |
$xml = simplexml_import_dom($doc); | |
$images = $xml->xpath('//img'); | |
foreach ($images as $img) { | |
echo " Image Source : " . $img['src'] . ""; | |
echo " Image Alt : " . $img['alt'] . ""; | |
echo " Image Title : " . $img['title'] . ""; | |
echo " Image Width : " . $img['data-src-width']. ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment