0

我有一个看起来像这样的 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.........featuredog (Extracting only image url) 之间的内容?欣赏任何代码示例。

4

2 回答 2

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];
?>
于 2013-04-24T13:00:55.097 回答
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']);
于 2013-04-24T15:27:53.807 回答