Johan Larsson
Johan Larsson

Reputation: 175

Extract external image url from Facebook rss feed

I have a Facebook page Feed that looks like this,

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

How to extract what comes between the &url.........featuredog (Extracting only image url) ? Appreciate any code example.

Upvotes: 0

Views: 300

Answers (2)

C3roe
C3roe

Reputation: 96151

$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']);

Upvotes: 1

JohnC--
JohnC--

Reputation: 306

my regex is ugly but does the trick:

<?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];
?>

Upvotes: 1

Related Questions