Skip to content

Instantly share code, notes, and snippets.

@trey8611
Created July 26, 2017 21:02
Show Gist options
  • Select an option

  • Save trey8611/3dcca4d76d681c05342b131d65de8e1d to your computer and use it in GitHub Desktop.

Select an option

Save trey8611/3dcca4d76d681c05342b131d65de8e1d to your computer and use it in GitHub Desktop.
Get all image src values from HTML
// 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