从Facebook rss feed中提取外部图像网址

时间:2013-04-24 10:51:23

标签: php facebook

我的Facebook页面Feed看起来像这样,

http://external.ak.fbcdn.net/safe_image.php?d=AQA-U_vFlmf0YW5c&w=130&h=130&url=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FX9Hx6nUTSwE%2Fmaxresdefault.jpg%3Ffeature%3Dog

如何提取& url ......... featureog(仅提取图片网址)之间的内容? 感谢任何代码示例。

2 个答案:

答案 0 :(得分:1)

我的正则表达式很丑陋,但却有诀窍:

<?php
$str = 'http://external.ak.fbcdn.net/safe_image.php?d=AQA-U_vFlmf0YW5c&w=130&h=130&url=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FX9Hx6nUTSwE%2Fmaxresdefault.jpg%3Ffeature%3Dog';

$str = urldecode($str);
preg_match_all('~&url=(.*?)[\?\!]?feature~i', $str, $matches, PREG_PATTERN_ORDER);

echo $matches[1][0];
?>

答案 1 :(得分:1)

$parts = parse_url('http://external.ak.fbcdn.net/safe_image.php?d=AQA-U_vFlmf0YW5c&w=130&h=130&url=http%3A%2F%2Fi1.ytimg.com%2Fvi%2FX9Hx6nUTSwE%2Fmaxresdefault.jpg%3Ffeature%3Dog');
parse_str($parts['query'], $params);
var_dump($params['url']);