我试图从twitter中抓取图片url 'https://pbs.twimg.com/media/BGZHCHwCEAACJ19.jpg:large'使用php。我发现下面的php代码和file_get_contents正在工作,但我不认为正则表达式是匹配的网址。你能帮助调试这段代码吗?提前致谢。使用PHP从twitter页面中刮取图片网址
以下是Twitter的一个片段包含影像:
<div class="media-gallery-image-wrapper">
<img class="large media-slideshow-image" alt="" src="https://pbs.twimg.com/media/BGZHCHwCEAACJ19.jpg:large" height="480" width="358">
</div>
这里是PHP代码:
<?php
$url = 'http://t.co/s54fJgrzrG';
$twitter_page = file_get_contents($url);
preg_match('/(http:\/\/p.twimg.com\/[^:]+):/i', $twitter_page, $matches);
$imgURL = array_pop($matches);
echo $imgURL;
?>
谢谢这个工程:) – 2013-03-27 23:25:16