public static function getExcerptFromHtml($html, $tag)
    {
        $doc = new \DOMDocument();
        $doc->loadHTML($html);
        $images = $doc->getElementsByTagName($tag);
        $excerpt = null;

        foreach ($images as $image) {
            $attributes = [];
            foreach ($image->attributes as $name => $value) {
                $attributes[$name] = $value->value;
            }
            $excerpt = [
                'element' => [
                    'name'       => $image->tagName,
                    'attributes' => $attributes
                ]
            ];
        }

        return $excerpt;
    }
public static function getExcerptFromHtml($html, $tag)
    {
        $doc = new \DOMDocument();
        $doc->loadHTML($html);
        $images = $doc->getElementsByTagName($tag);
        $excerpt = null;

        foreach ($images as $image) {
            $attributes = [];
            foreach ($image->attributes as $name => $value) {
                $attributes[$name] = $value->value;
            }
            $excerpt = [
                'element' => [
                    'name'       => $image->tagName,
                    'attributes' => $attributes
                ]
            ];
        }

        return $excerpt;
    }
public static function getExcerptFromHtml ( $ html , $ tag ) { $ doc = new \ DOMDocument ( ) ; $ doc -> loadHTML ( $ html ) ; $ images = $ doc -> getElementsByTagName ( $ tag ) ; $ excerpt = null ; foreach ( $ images as $ image ) { $ attributes = [ ] ; foreach ( $ image -> attributes as $ name => $ value ) { $ attributes [ $ name ] = $ value -> value ; } $ excerpt = [ 'element' => [ 'name' => $ image -> tagName , 'attributes' => $ attributes ] ] ; } return $ excerpt ; }
Get an Excerpt array from a chunk of HTML

@param string $html         Chunk of HTML
@param string $tag          A tag, for example `img`
@return array|null   returns nested array excerpt
Get an Excerpt array from a chunk of HTML