bludit/bl-kernel/helpers/dom.class.php

27 lines
604 B
PHP
Raw Permalink Normal View History

<?php defined('BLUDIT') or die('Bludit CMS.');
class DOM {
public static function getFirstImage($content)
{
2017-10-21 20:30:59 +02:00
// Disable warning
2017-10-21 20:35:45 +02:00
libxml_use_internal_errors(true);
$dom = new DOMDocument();
$dom->loadHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8">'.$content);
$finder = new DomXPath($dom);
$images = $finder->query("//img");
if($images->length>0) {
// First image from the list
$image = $images->item(0);
// Get value from attribute src
$imgSrc = $image->getAttribute('src');
// Returns the image src
return $imgSrc;
}
return false;
}
}