trey8611
7/26/2017 - 9:02 PM

Get all image src values from HTML

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 );
}