user1116921
user1116921

Reputation:

PHP - Grab image url from RSS feed

I have an RSS feed which has an image and some text. I want to grab only the URL from the image and put it into a variable.

I guess the image is on the description of the feed, how can I do to grab it? I tried getting it with regular expression and it didn't work. How can I do this properly with regular expression so I can only get the src="" part.

<?php
    $feed = simplexml_load_file("the_feed");
    foreach ($feed->channel->item as $item)
    {
        $description = $item->description;
    }
?>

Maybe I should use something like:

$imgpattern = '/src="(.*?)"/i';
preg_match($imgpattern, $description, $matches);
$imageurl['image'] = $matches[1];
echo $imageurl['image'];

Upvotes: 0

Views: 1276

Answers (1)

Mr. BeatMasta
Mr. BeatMasta

Reputation: 1312

I think you have already answered your question :))) only thing is that the regex you want to use is not so good I guess, better is this $imgpattern = '/src="([^"]+)"/i';

Upvotes: 1

Related Questions