来自RSS Feed的图像使用DOM文档

时间:2015-10-09 07:53:04

标签: javascript php wordpress dom rss

我正在尝试构建一个自定义RSS Feed显示器,它与图像完美分开。我可以看到RSS提要显示如下图像:

<description><![CDATA[<img width="150" height="150" src="/blog/wp-content/uploads/2015/10/image.jpg" class="attachment-thumbnail wp-post-image" alt="" style="display: block; margin-bottom: 5px; clear:both;" /><p></p>
]]></description>

这是我用来获取RSS提要的代码,没有图像部分工作。任何帮助都会很棒!

                    $rss = new DOMDocument();
                    $rss->load('/blog/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,
                            'image' => $node->getElementsByTagName('image')->item(0)->nodeValue,
                            'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
                            );
                        array_push($feed, $item);
                    }
                    $limit = 4;
                    for($x=0;$x<$limit;$x++) {
                        $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
                        $link = $feed[$x]['link'];
                        $description = $feed[$x]['desc'];
                        $date = date('l F d, Y', strtotime($feed[$x]['date']));
                        $image = $feed[$x]['image'];

                        ?>
                        <div class="row">
                            <div class="col-md-4 col-sm-12 col-xs-12">
                                <img src="/img/<?php echo $image ?>.jpg" class="blogImages" alt="<?php echo $title ?>" title="<?php echo $title ?>">
                            </div>

0 个答案:

没有答案