Created
July 26, 2017 21:02
-
-
Save trey8611/3dcca4d76d681c05342b131d65de8e1d to your computer and use it in GitHub Desktop.
Get all image src values from HTML
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
| // Get all image src from HTML content | |
| function my_get_images_from_content( $html ) { | |
| $doc = new DOMDocument(); | |
| @$doc->loadHTML( $html ); | |
| $imageTags = $doc->getElementsByTagName( 'img' ); | |
| $all_images = array(); | |
| foreach( $imageTags as $tag ) { | |
| $all_images[] = $tag->getAttribute( 'src' ); | |
| } | |
| return implode( ",", $all_images ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment