获取元标题,描述&图片。

时间:2014-04-22 08:50:44

标签: php

我有一个文本框,允许用户发布网址

file_get_contents_curl($url);

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

它会显示网址中的所有图片,我只想显示此网址中包含的og:图片的图片代码。

1 个答案:

答案 0 :(得分:0)

您可以获得此代码的第一个匹配项。

$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;