PHP code example of seffeng / rss
1. Go to this page and download the library: Download seffeng/rss library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
seffeng / rss example snippets
/**
* TestController.php
* 示例
*/
namespace App\Http\Controllers;
use Seffeng\Rss\Rss;
class TestController extends Controller
{
public function index()
{
$channel = [
'title' => '频道名称。人们就是这样引用您的服务的。如果您的HTML网站包含与RSS文件相同的信息,则频道标题应与网站标题相同。',
'link' => 'https://www.wuhuawu.com/rss',
'description' => '描述频道的词组或句子。',
'copyright' => 'copyright',
'language' => 'zh-cn',
'ttl' => 30,
'generator' => '峰雪幽忧',
'xmlns' => [
'atom:link' => [
'href' => 'https://www.wuhuawu.com',
'rel' => 'self',
'type' => 'application/rss+xml'
],
'atom:link2' => [
'href' => 'https://www.wuhuawu.com',
'rel' => 'self',
'type' => 'application/rss+xml'
],
],
];
$item = [
['title' => 'composer 本地包引入', 'link' => 'https://www.wuhuawu.com/view/150', 'source' => ['text' => '链接来源', 'url' => 'https://www.wuhuawu.com'], 'pubDate' => 1665555555, 'guid' => 'https://www.wuhuawu.com/view/150'],
['title' => 'iptables配置模版', 'link' => 'https://www.wuhuawu.com/view/116', 'category' => 'linux', 'description' => '<span style="color: #f00">iptables配置模版</span><br /><pre>iptables -A INPUT -p tcp --dport 80 -j ACCEPT</pre>', 'source' => ['text' => '来源2', 'url' => 'https://www.wuhuawu.com/rss'], 'pubDate' => '2020-11-13 11:46', 'guid' => 'https://www.wuhuawu.com/view/116'],
];
header('content-type:text/xml');
print_r((new Rss())->toRss($channel, $item));exit;
}
}
└─src
├─Rss.php
└─Contracts
Channel.php
Item.php