淡入淡出,使用PHP循环RSS新闻源


Fade in/out, cycling RSS news feed using PHP

我有一些显示RSS项目的PHP代码,我将其限制为1。我想让代码在我的RSS项目中循环,并具有淡入淡出效果。我可能可以计算出淡出的jQuery,但让它循环是我的主要问题。

<?php
$rss = new DOMDocument();
$rss->load('http://www.huffingtonpost.com/feeds/news.xml');
$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
    );
    array_push($feed, $item);
}
$limit = 1;
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']));
    echo '<br><p><strong><a href="' . $link . '" title="' . $title . '">' . $title . '</a></strong><br>' . $description . '</p>';
}
?>

这是一个简单的问题,您的$limit是静态的,并设置为1。要查找数组值的数量,请使用count((:

$limit = count($feed);