【发布时间】:2013-09-21 08:25:09
【问题描述】:
我正在尝试使用 php 从 Instagram 网址中抓取图片网址。图片网址似乎包含在页面顶部的元标记中,如下所示:
<meta property="og:image" content="http://distilleryimage10.ak.instagram.com/9e4360c6220411e38abf22000a1f9bf5_7.jpg" />
从此我想返回内容部分,例如http://distilleryimage10.ak.instagram.com/9e4360c6220411e38abf22000a1f9bf5_7.jpg
我需要为多个图像执行此操作,因此即使 url 发生更改,我也需要提取此图像。
我目前的代码是
$page = file_get_contents('http://instagram.com/p/efH-NVOTAy/#');
preg_match("/og:image/", $page, $matches);
print_r($matches);
这将打印 Array ( [0] => og:image )
只要它匹配 'og:image' 就可以工作,并向我确认它可以在从 file_get_contents 返回的数据中找到这个字符串,但我不确定如何实现从这一行返回 url 的飞跃?
【问题讨论】:
标签: php regex preg-match instagram