Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的RSS阅读器,一些问题_Php_Rss - Fatal编程技术网

PHP中的RSS阅读器,一些问题

PHP中的RSS阅读器,一些问题,php,rss,Php,Rss,一开始我对我的语言感到抱歉,但英语不是我的母语:) 所以,现在我正在为我的网站做一个RSS阅读器。但在这期间,我遇到了一些问题 1) 如何按时间顺序显示新闻?我的意思是,现在我把一切都混在一起了——最新的新闻可以放在专栏的底部,最老的新闻可以放在专栏的顶部 2) 如何设置显示新闻的限制?例如,我只想显示10个项目 3) 我如何显示一些新闻的来源?我的意思是,现在我只有标题和日期,但我想向其他人展示这条新闻也是从哪个网站发布的 提前谢谢!你好 显示RSS新闻: ` addFeeds($url);

一开始我对我的语言感到抱歉,但英语不是我的母语:)

所以,现在我正在为我的网站做一个RSS阅读器。但在这期间,我遇到了一些问题

1) 如何按时间顺序显示新闻?我的意思是,现在我把一切都混在一起了——最新的新闻可以放在专栏的底部,最老的新闻可以放在专栏的顶部

2) 如何设置显示新闻的限制?例如,我只想显示10个项目

3) 我如何显示一些新闻的来源?我的意思是,现在我只有标题和日期,但我想向其他人展示这条新闻也是从哪个网站发布的

提前谢谢!你好

显示RSS新闻:

`

addFeeds($url);
$feeds->grabss();
$feeds->mergage();
$feeds\u pl=新的Feed\u合并器;
$feeds\u pl->addFeeds($url\u pl);
$feeds_pl->grabss();
$feeds_pl->合并();
}
捕获(例外$e)
{
死亡($e->getMessage());
}
?> 


  • `

  • FEEDS.PHP文件

      <script type="text/javascript">
    function showonlyone(thechosenone) {
        var newboxes = document.getElementsByTagName("div");
        for(var x=0; x<newboxes.length; x++) {
            name = newboxes[x].getAttribute("class");
            if (name == 'newboxes') {
                if (newboxes[x].id == thechosenone) {
                    newboxes[x].style.display = 'block';
                }
                else {
                    newboxes[x].style.display = 'none';
                }
            }
        }
    }
    </script>
    
    <?php class Feed_Amalgamator
    {
    public $urls = array();
    public $data = array();
    
    public function addFeeds( array $feeds )
    {
        $this->urls = array_merge( $this->urls, array_values($feeds) );
    }
    
    public function grabRss()
    {
        foreach ( $this->urls as $feed )
        {
            $data = @new SimpleXMLElement( $feed, 0, true );
            if ( !$data )
            throw new Exception( 'Could not load: ' . $feed );
            foreach ( $data->channel->item as $item )
            {
                $this->data[] = $item;
            }
        }
    }
    
    public function amalgamate()
    {
        shuffle( $this->data );
        $temp = array();
        foreach ( $this->data as $item )
            {
                if ( !in_array($item->link, $this->links($temp)) )
                {
                    $temp[] = $item;
                }
        }
        $this->data = $temp;
        shuffle( $this->data );
    }
    
    private function links( array $items )
    {
        $links = array();
        foreach ( $items as $item )
        {
            $links[] = $item->link;
        }
        return $links;
        }
    }
    ?>
    
    
    功能仅显示一个(氯乙烯酮){
    var newbox=document.getElementsByTagName(“div”);
    对于(var x=0;xchannel->item作为$item)
    {
    $this->data[]=$item;
    }
    }
    }
    公共职能合并()
    {
    洗牌($this->data);
    $temp=array();
    foreach($this->data as$item)
    {
    如果(!在数组中($item->link,$this->links($temp)))
    {
    $temp[]=$item;
    }
    }
    $this->data=$temp;
    洗牌($this->data);
    }
    专用函数链接(数组$项)
    {
    $links=array();
    foreach($items作为$item)
    {
    $links[]=$item->link;
    }
    返回$links;
    }
    }
    ?>
    
    simplepie提要解析器是您最好的朋友:

      <script type="text/javascript">
    function showonlyone(thechosenone) {
        var newboxes = document.getElementsByTagName("div");
        for(var x=0; x<newboxes.length; x++) {
            name = newboxes[x].getAttribute("class");
            if (name == 'newboxes') {
                if (newboxes[x].id == thechosenone) {
                    newboxes[x].style.display = 'block';
                }
                else {
                    newboxes[x].style.display = 'none';
                }
            }
        }
    }
    </script>
    
    <?php class Feed_Amalgamator
    {
    public $urls = array();
    public $data = array();
    
    public function addFeeds( array $feeds )
    {
        $this->urls = array_merge( $this->urls, array_values($feeds) );
    }
    
    public function grabRss()
    {
        foreach ( $this->urls as $feed )
        {
            $data = @new SimpleXMLElement( $feed, 0, true );
            if ( !$data )
            throw new Exception( 'Could not load: ' . $feed );
            foreach ( $data->channel->item as $item )
            {
                $this->data[] = $item;
            }
        }
    }
    
    public function amalgamate()
    {
        shuffle( $this->data );
        $temp = array();
        foreach ( $this->data as $item )
            {
                if ( !in_array($item->link, $this->links($temp)) )
                {
                    $temp[] = $item;
                }
        }
        $this->data = $temp;
        shuffle( $this->data );
    }
    
    private function links( array $items )
    {
        $links = array();
        foreach ( $items as $item )
        {
            $links[] = $item->link;
        }
        return $links;
        }
    }
    ?>