I have been looking on here for a solution to my problem but nothing seems to work :(
I have the following code
<?php
$rss = new DOMDocument();
$rss->load('http://thelostgirl2014.wordpress.com/feed/');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node)
{
$item = array (
'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
'content' => $node->getElementsByTagName('encoded')->item(0)->nodeValue,
'comments' => $node->getElementsByTagName('comments')->item(0)->nodeValue,
'photos' => $node->getElementsByTagNameNS('http://thelostgirl2014.wordpress.com/feed/', 'content')->item(0),
);
array_push($feed, $item);
}
$limit = 3;
for($x=0;$x<$limit;$x++)
{
$title = str_replace(' & ', ' & ', $feed[$x]['title']);
$link = $feed[$x]['link'];
$description = $feed[$x]['desc'];
$content = $feed[$x]['content'];
$comments = $feed[$x]['comments'];
$photos = $feed[$x]['photos'];
$date = date('l F d, Y', strtotime($feed[$x]['date']));?>
<div class="feed">
<div class="feed-title">
<a href="<?php echo $link?>" title="<?php echo $title?>"><?php echo $title?></a>
</div>
<div class="feed-date">
<small><em>Posted on <?php echo $date?></em></small>
</div>
<div class="feed-description">
<?php echo $photos?>
</div>
</div><?php
}?>
and it pulls out the main node values but i cant get the namespace values.
Im trying to get the media url so i can display the image(s) on my php page but the current code
'photos' => $node->getElementsByTagNameNS('http://thelostgirl2014.wordpress.com/feed/', 'content')->item(0),
returns nothing :(
here is a snippet from the blog im trying to retreive the data
<item>
<title>Achievements</title>
<link>http://thelostgirl2014.wordpress.com/2014/01/13/achievements/</link>
<comments>http://thelostgirl2014.wordpress.com/2014/01/13/achievements/#comments</comments>
<pubDate>Mon, 13 Jan 2014 03:20:32 +0000</pubDate>
<dc:creator><![CDATA[thelostgirl2014]]></dc:creator>
<category><![CDATA[Uncategorized]]></category>
<guid isPermaLink="false">https://thelostgirl2014.wordpress.com/?p=8</guid>
<description><![CDATA[Well, in the last few months I have achieved so much…from joining a cruiseship to simply eating prawns!! I have never been a prawn fan, never liked the look of them so never tried them! But today, at Mozarts Restaurant in Funchal, Madeira I had a fresh mushroom and prawn risotto which was delicious! To […]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelostgirl2014.wordpress.com&blog=62611577&post=8&subd=thelostgirl2014&ref=&feed=1" width="1" height="1" />]]></description>
<content:encoded><![CDATA[<p><a href="http://thelostgirl2014.files.wordpress.com/2014/01/20140113-031825-am.jpg"><img src="http://thelostgirl2014.files.wordpress.com/2014/01/20140113-031825-am.jpg?w=696" alt="20140113-031825 am.jpg" class="alignnone size-full" /></a></p>
<p>Well, in the last few months I have achieved so much…from joining a cruiseship to simply eating prawns!! </p>
<p>I have never been a prawn fan, never liked the look of them so never tried them!<br />
But today, at Mozarts Restaurant in Funchal, Madeira I had a fresh mushroom and prawn risotto which was delicious! </p>
<p>To me this is a massive step for me, I have always been afraid of trying new food but seeing as I’m away I’m keen to try new things…so prawns are my latest thing…<br />
The best thing was…the three course meal came with free champagne and wine woohoo!! Bonus!! €37 well spent me thinks!!</p><br /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/thelostgirl2014.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/thelostgirl2014.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelostgirl2014.wordpress.com&blog=62611577&post=8&subd=thelostgirl2014&ref=&feed=1" width="1" height="1" />]]></content:encoded>
<wfw:commentRss>http://thelostgirl2014.wordpress.com/2014/01/13/achievements/feed/</wfw:commentRss>
<slash:comments>0</slash:comments>
<georss:point>32.642638 -16.923540</georss:point>
<geo:lat>32.642638</geo:lat>
<geo:long>-16.923540</geo:long>
<media:content url="http://2.gravatar.com/avatar/5f747606b6bc78986250229230fe693f?s=96&d=identicon&r=G" medium="image">
<media:title type="html">thelostgirl2014</media:title>
</media:content>
<media:content url="http://thelostgirl2014.files.wordpress.com/2014/01/20140113-031825-am.jpg" medium="image">
<media:title type="html">20140113-031825 am.jpg</media:title>
</media:content>
</item>
any help to return the media url would be great, Luke
You had better change the way you are doing as follow: $curl = curl_init();
curl_setopt_array($curl, Array(
CURLOPT_URL => 'http://thelostgirl2014.wordpress.com/feed/',
CURLOPT_USERAGENT => 'spider',
CURLOPT_TIMEOUT => 120,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_ENCODING => 'UTF-8'
));
$data = curl_exec($curl);
curl_close($curl);
$feed = array();
$xml = simplexml_load_string($data, 'SimpleXMLElement', LIBXML_NOCDATA);
foreach ( $xml->channel->item as $item ) {
$creator = $item->children('dc', TRUE);
$item = array (
'title' => $item->title,
'desc' => $item->description,
'author'=> $creator,
'link' => $item->link
);
array_push($feed, $item);
}
All the answers on SO say to use SimpleXMLELement. But what if I don't want too!
Here is the answer:
$node->getElementsByTagNameNS('*', 'thumbnail')->item(0)