获取函数的输出
I aggregate all my new posts from several sites into a single RSS feed. Last time I updated my homepage, I came across an idea why not showing these feed items directly on the homepage as HTML content. After some study, I got one single PHP function in my hand that fetches an RSS feed and outputs HTML content in the page.
我将来自多个站点的所有新帖子汇总到一个RSS feed中。 上次更新首页时 ,我遇到一个想法,为什么不将这些提要项直接显示为HTML内容在首页上。 经过一番研究,我手中只有一个PHP函数,该函数获取RSS feed并在页面中输出HTML内容。

The PHP fuction and one example are as follows.
PHP功能和一个示例如下。
The single PHP function that gets RSS feed and converts it to HTML. Another helper function that outputs the HTML content.
单个PHP函数,用于获取RSS feed并将其转换为HTML。 另一个输出HTML内容的辅助函数。
One usage example:
一个用法示例:
<?php
// output RSS feed to HTML
output_rss_feed('http://feeds.systutorials.com/ericfeed', 20, true, true, 200);
?>
Here is one example showing how to use this script.
这是显示如何使用此脚本的一个示例 。
The comments in the code should explain what it does well. You can call the output_rss_feed
with the feed link and other options at the place where you would show the RSS feed.
代码中的注释应说明其功能。 您可以在显示RSS feed的地方使用feed链接和其他选项调用output_rss_feed
。
This function also supports a simple caching mechanism so that not every call to the same RSS feed will invoke a network request.
此功能还支持简单的缓存机制,因此并非每个对同一RSS feed的调用都会调用网络请求。
For the style of the items displayed, you may customize your site’s CSS file or add add a style tag to control the styles. The code already generate class names for most items. Here is one example of the CSS for customizing the style of the displayed feed items.
对于所显示项目的样式 ,您可以自定义网站CSS文件或添加添加样式标签来控制样式。 该代码已经为大多数项目生成了类名。 这是CSS的一个示例,用于自定义显示的供稿项的样式。
.feed-description {padding-left:10px;margin-left:10px;border-left:2px solid #eee;}
.feed-lists {padding-left:1em;}
.feed-item-image {max-width: 300px; max-height: 200px; float: right; margin-left: 10px; }
翻译自: https://www.systutorials.com/a-php-function-for-fetching-rss-feed-and-outputing-feed-items-as-html/
获取函数的输出