我有一个文本框,允许用户张贴的网址
file_get_contents_curl($url);$image_regex = '/<img[^>]*'.'src=[\"|\'](.*)[\"|\']/Ui';
它显示了url中的所有图像,我只想显示这个url中包含的og:image的图像标记。
发布于 2014-04-22 17:01:01
您可以使用此代码获得第一个匹配项。
$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;https://stackoverflow.com/questions/23214780
复制相似问题