I am trying to incorporate my pin feed into my site. I have got it working but I need to amend what it shows as it's not quite working as intended.
What I need is to extract a certain piece of data from the description bit of the date.
This is the code I use to grab my XML feed:
<?php
$ch = curl_init("http://pinterest.com/1234/feed.rss");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);
$doc = new SimpleXmlElement($data, LIBXML_NOCDATA);
if(isset($doc->channel))
{
parseRSS($doc);
}
function parseRSS($xml)
{
$cnt = 9;
for($i=0; $i<$cnt; $i++)
{
$url = $xml->channel->item[$i]->link;
$img = $xml->channel->item[$i]->description;
$title = $xml->channel->item[$i]->title;
echo '<p><a href="'.$url.'" title="'.$title.'">'.$img.'</a></p>';
}
}
?>
The problem is that description looks like below and all I want is the src
value from it:
<description><p><a href="/pin/1785432765530/"><img src="http://media-cache-ec1.pinterest.com/upload/27099622222548513383_qJV62266Pf_b.jpg"></a></p><p>What it takes to Google’s.</p></description>
Is there a way to just get src="http://media-cache-ec1.pinterest.com/upload/270996666522513383_qJV6666Pf_b.jpg"
out of the description and store it in $img
or another variable?