loadHTML( '' . $content . '', \LIBXML_HTML_NOIMPLIED | \LIBXML_HTML_NODEFDTD ); \libxml_use_internal_errors( $use_error ); foreach ( [ 'embed', 'iframe', 'img', 'object' ] as $tag ) { /** @var \DOMElement $element */ foreach ( $dom->getElementsByTagName( $tag ) as $element ) { $height = $element->getAttribute( 'height' ); $width = $element->getAttribute( 'width' ); if ( $height && $width ) { return [ 'height' => $height, 'width' => $width, ]; } } } return []; } /** * Get an oEmbed title by its title attribute. * * @param string $content The content to get the title of * @return string The title or an empty string */ public static function get_title( $content ) { $use_error = \libxml_use_internal_errors( true ); $dom = new DOMDocument(); $dom->loadHTML( '' . $content . '', \LIBXML_HTML_NOIMPLIED | \LIBXML_HTML_NODEFDTD ); \libxml_use_internal_errors( $use_error ); foreach ( [ 'embed', 'iframe', 'object' ] as $tag ) { /** @var \DOMElement $element */ foreach ( $dom->getElementsByTagName( $tag ) as $element ) { $title = $element->getAttribute( 'title' ); if ( $title ) { return $title; } } } return ''; } }