我正在尝试从某些网页的标记中抓取图像。这些网页都有幻灯片。它们的来源包含在页面上的 javascript 对象中。我在想我需要 get_file_contents("http://www.example.com/page/1"); 然后有一个 preg_match_all() 函数,我可以输入一个短语(即 "\"LargeUrl\":\"" 或 "\"Description\":\"")并获取字符串直到它命中它找到的下一个引号。
var photos = {};
photos['photo-391094'] = {"LargeUrl": "http://www.example.org/images/1.png","Description":"blah blah balh"};
photos['photo-391095'] = {"LargeUrl": "http://www.example.org/images/2.png","Description":"blah blah balh"};
photos['photo-391096'] = {"LargeUrl": "http://www.example.org/images/3.png","Description":"blah blah balh"};
我有这个函数,但它在输入短语之后返回整行。我如何修改它以查找输入短语之后的任何内容,直到它找到找到的下一个引号?还是我做错了,有更好的方法吗?
$page = file_get_contents("http://www.example.org/page/1");
$word = "\"LargeUrl\":\"";
if(preg_match_all("/(?<=$word)\S+/i", $page, $matches))
{
echo "<pre>";
print_r($matches);
echo "</pre>";
}
理想情况下,如果我输入 "\"LargeUrl\":\"",该函数将返回如下所示的数组
$matches[0] = "http://www.example.org/images/1.png";
$matches[1] = "http://www.example.org/images/2.png";
$matches[2] = "http://www.example.org/images/3.png";