отображение фида WordPress с использованием DOMDocument - не удается получить значения пространства имен

Я искал здесь решение своей проблемы, но ничего не работает :(

У меня есть следующий код

<?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(' & ', ' &amp; ', $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
}?>

и он извлекает основные значения узла, но я не могу получить значения пространства имен.

Я пытаюсь получить URL-адрес мультимедиа, чтобы отображать изображения на моей php-странице, но текущий код

'photos' => $node->getElementsByTagNameNS('http://thelostgirl2014.wordpress.com/feed/', 'content')->item(0),

ничего не возвращает :(

вот фрагмент из блога, в котором я пытаюсь восстановить данные

<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&#8230;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 [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=thelostgirl2014.wordpress.com&#038;blog=62611577&#038;post=8&#038;subd=thelostgirl2014&#038;ref=&#038;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&#8230;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&#8217;m away I&#8217;m keen to try new things&#8230;so prawns are my latest thing&#8230;<br />
The best thing was&#8230;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&#038;blog=62611577&#038;post=8&#038;subd=thelostgirl2014&#038;ref=&#038;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&#38;d=identicon&#38;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>

любая помощь, чтобы вернуть URL-адрес мультимедиа, была бы отличной, Люк


person user2886669    schedule 05.02.2014    source источник


Ответы (2)


Вам лучше изменить способ, которым вы это делаете, следующим образом: $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);
    }
person Community    schedule 28.02.2014

Все ответы на SO говорят об использовании SimpleXMLELement. А если я тоже не хочу!

Вот ответ:

$node->getElementsByTagNameNS('*', 'thumbnail')->item(0)
person Tim S.    schedule 19.01.2015