RSS中每个类别的PHP 1元素

时间:2010-09-24 07:33:10

标签: php rss

伙计们,我有这样的事情:

$rss->feed = "http://nola.gosimian.com/rss_content.php";                
        if (!$rss->parse())
              echo $rss->error;


        $column_count = 0;            
        $i=0;  
        while($i < 25)
        {       


            $title      = $rss->channel['ITEM'][$i]['TITLE'];
            $item_id        = $rss->channel['ITEM'][$i]['ITEMID'];
            $title_clean = ereg_replace("[[:space:]]", "", $title);             
            $credits    =  str_replace(' -cmd- ',',', $rss->channel['ITEM'][$i]['COMMENTS']);
            $credits_clean = str_replace(',Director||','', $credits);
            $credits_clean = ereg_replace("[[:space:]]", "-", $credits_clean);
            $desc       =  $rss->channel['ITEM'][$i]['DESCRIPTION'];
            $thumbnail  =  $rss->channel['ITEM'][$i]['SOURCE'];
            $media      =  $rss->channel['ITEM'][$i]['ENCLOSURE']['URL'];
            $date       =  $rss->channel['ITEM'][$i]['PUBDATE'];    
            foreach($date as $date) {
            echo '<a href="'.get_option('home').'/player/'.$credits_clean.'/' . $item_id . '" title="' . $title . '"><img src="' . $thumbnail . '" width="190" height="115" class="thumbnail"></a>';                       
            $column_count++;        
            $i++;           
            }
            /*if($column_count == 3)
            {
                echo '</tr><tr>';
                $column_count = 0;
            }*/

        }

是否可以仅为每个“导演”元素显示RSS的一个项目/条目(如果有12个导演,则显示12个视频)。 ?

非常感谢!!

1 个答案:

答案 0 :(得分:0)

您可以做的是将$credits的值存储在while循环中的数组中。如果您点击了已经输出的信用额度,只需continue到下一个元素。

$creditsSeen = array();
while($i < 25) {
    ...
    $credits_clean = ...
    if (in_array($credits_clean, $creditsSeen)) {
        $i++; // perhaps you need to increment $column_count as well?
        continue;
    } else {
        $creditsSeen[] = $credits_clean;
    }
    ...
}

免责声明我不完全确定这就是您的要求。如果在您的情况下无法使用,请详细说明您的问题:)