php 聚合来自github帐户的RSS提要

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 聚合来自github帐户的RSS提要相关的知识,希望对你有一定的参考价值。

<?php

// function for sorting by date
function date_compare($a, $b)
	{
    $t1 = strtotime($a['published']);
    $t2 = strtotime($b['published']);
    return $t2 - $t1;
	}    

// add any users I want
$user_array = array('kinlane','apievangelist','streamdataio');
$feed_array = array();

// loop through my users
foreach($user_array as $user)
	{
		
	// pull the RSS feeds	
	$rss_feed = 'https://github.com/' . $user . '.atom';
	$github_rss = file_get_contents($rss_feed);
	$github_object = simplexml_load_string($github_rss);
	
	foreach($github_object->entry as $entry)
		{
		
		// establish local values, in case I want to do something else
		$id = $entry->id->__toString();
		$published = $entry->published->__toString();
		$link = $entry->link["href"]->__toString();
		$title = $entry->title->__toString();
		$author_name = $entry->author->name->__toString();
		$author_url = $entry->author->uri->__toString();

		// create an array
		$item = array();
		$item['id'] = $id;
		$item['published'] = $published;
		$item['title'] = $title;
		$item['link'] = $link;
		$item['author_name'] = $author_name;
		$item['author_url'] = $author_url;

		// add the individual entry
		array_push($feed_array,$item);	
			
		}
	}

// sort the collection of feeds
usort($feed_array, 'date_compare');

// publish as json
$feed_json = json_encode($feed_array);
echo $feed_json;
?>

以上是关于php 聚合来自github帐户的RSS提要的主要内容,如果未能解决你的问题,请参考以下文章

设置 Github Commit RSS 提要

将图像添加到 RSS 提要的正确方法?

设置Github Commit RSS提要

sh 监视RSS提要以获取来自bash的更改

带有 PHP 的 Spotify 的 RSS 提要

解析 XML(RSS 提要)的 PHP 错误