2017-10-13 23:38:24 +02:00
|
|
|
<?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);
|
2017-10-13 23:38:24 +02:00
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|