获取元标题,描述&;图像


Get Meta-Title, Description & Images.

我有一个文本框,允许用户发布url的

file_get_contents_curl($url);

$image_regex = '/<img[^>]*'.'src=['"|''](.*)['"|'']/Ui';

它显示了url中的所有图像,我只想显示这个url中包含的og:image的图像标记。

您可以使用此代码获得第一个匹配。

$url = 'http://stackoverflow.com/';
$content = file_get_contents($url);
$image_regex = '/<img[^>]*'.'src=['"|''](.*)['"|'']/Ui';

preg_match($image_regex, $content, $matches);
$firstImage = strip_tags($matches[1]); // Get first match
echo $firstImage;