HTML - RSS・Atom - PHP で作成する - 少しカスタマイズしてみる
1. 少しカスタマイズしてみる 前の結果を踏まえて、少しカスタマイズしてみます。 <?php require '../vendor/autoload.php'; $rss = new UniversalFeedCreator(); $rss->title = "FreeBSD あれこれ"; $rss->description = "FreeBSD をはじめ OS・サーバ・アプリケーション等の紹介サイト。"; $rss->link = "https://freebsd.sing.ne.jp/"; // FeedImage はなくて良さそう // 実際にはデータベースから取得する仕組みにするにしても・・・ // どんな風に出るかをみてみたい $item = new FeedItem(); $item->title = '共通事項'; $item->link = 'https://freebsd.sing.ne.jp/00/'; $item->description = 'ももも'; $date = new DateTime(); $item->date = $date->getTimestamp(); // $item->source = "http://www.dailyphp.net"; これが必要なのかがわからない・・・ $item->author = "Show.Kit"; $rss->addItem($item); $rss->saveFeed('RSS1.0', 'output/rss10.xml', false); $rss->saveFeed('RSS2.0', 'output/rss20.xml', false); $rss->saveFeed('ATOM', 'output/atom.xml', false); ?> 2. 出力結果 上記のソースを実行すると下記の結果が得られます。 RSS1.0 形式で出力するとこういう形式 <?xml version="1.0" encoding="UTF-8"?> <!-- generator="FeedCreator 1.8" --> <?xml-stylesheet href="http://www.w3.org/2000/08/w3c-synd/style.css" type="text/css"?> <rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel rdf:about=""> <title>FreeBSD あれこれ</title> <description>FreeBSD をはじめ OS・サーバ・アプリケーション等の紹介サイト。</description> <link>https://freebsd.sing.ne.jp/</link> <dc:date>2018-10-23T17:27:13+0900</dc:date> <items> <rdf:Seq> <rdf:li rdf:resource="https://freebsd.sing.ne.jp/00/"/> </rdf:Seq> </items> </channel> <item rdf:about="https://freebsd.sing.ne.jp/00/"> <dc:format>text/html</dc:format> <dc:date>2018-10-23T08:27:13+0900</dc:date> <dc:creator>Show.Kit</dc:creator> <title>共通事項</title> <link>https://freebsd.sing.ne.jp/00/</link> <description>ももも</description> </item> </rdf:RDF> RSS2.0 形式で出力するとこういう形式 <?xml version="1.0" encoding="UTF-8"?> <!-- generator="FeedCreator 1.8" --> <rss version="2.0"> <channel xmlns:g="http://base.google.com/ns/1.0"> <title>FreeBSD あれこれ</title> <description>FreeBSD をはじめ OS・サーバ・アプリケーション等の紹介サイト。</description> <link>https://freebsd.sing.ne.jp/</link> <lastBuildDate>Tue, 23 Oct 2018 17:27:13 +0000</lastBuildDate> <generator>FeedCreator 1.8</generator> <item> <title>共通事項</title> <link>https://freebsd.sing.ne.jp/00/</link> <description>ももも</description> <pubDate>Tue, 23 Oct 2018 08:27:13 +0000</pubDate> </item> </channel> </rss> Atom 形式で出力するとこういう形式 <?xml version="1.0" encoding="utf-8"?> <!-- generator="FeedCreator 1.8" --> <feed xmlns="http://www.w3.org/2005/Atom"> <title>FreeBSD あれこれ</title> <subtitle>FreeBSD をはじめ OS・サーバ・アプリケーション等の紹介サイト。</subtitle> <link rel="alternate" type="text/html" href="https://freebsd.sing.ne.jp/"/> <id>https://freebsd.sing.ne.jp/</id> <updated>2018-10-23T17:27:13+0900</updated> <generator>FeedCreator 1.8 (info@mypapit.net)</generator> <link rel="self" type="application/atom+xml" href="" /> <entry> <title>共通事項</title> <link rel="alternate" type="text/html" href="https://freebsd.sing.ne.jp/00/"/> <published>2018-10-23T08:27:13+0900</published> <updated>2018-10-23T08:27:13+0900</updated> <id>https://freebsd.sing.ne.jp/00/</id> <author> <name>Show.Kit</name> </author> <content>ももも</content> <summary>ももも</summary> </entry> </feed> 「Atom」形式のものを「RSS」リーダで見てみると
<?php require '../vendor/autoload.php'; $rss = new UniversalFeedCreator(); $rss->title = "FreeBSD あれこれ"; $rss->description = "FreeBSD をはじめ OS・サーバ・アプリケーション等の紹介サイト。"; $rss->link = "https://freebsd.sing.ne.jp/"; // FeedImage はなくて良さそう // 実際にはデータベースから取得する仕組みにするにしても・・・ // どんな風に出るかをみてみたい $item = new FeedItem(); $item->title = '共通事項'; $item->link = 'https://freebsd.sing.ne.jp/00/'; $item->description = 'ももも'; $date = new DateTime(); $item->date = $date->getTimestamp(); // $item->source = "http://www.dailyphp.net"; これが必要なのかがわからない・・・ $item->author = "Show.Kit"; $rss->addItem($item); $rss->saveFeed('RSS1.0', 'output/rss10.xml', false); $rss->saveFeed('RSS2.0', 'output/rss20.xml', false); $rss->saveFeed('ATOM', 'output/atom.xml', false); ?>
<?xml version="1.0" encoding="UTF-8"?> <!-- generator="FeedCreator 1.8" --> <?xml-stylesheet href="http://www.w3.org/2000/08/w3c-synd/style.css" type="text/css"?> <rdf:RDF xmlns="http://purl.org/rss/1.0/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/"> <channel rdf:about=""> <title>FreeBSD あれこれ</title> <description>FreeBSD をはじめ OS・サーバ・アプリケーション等の紹介サイト。</description> <link>https://freebsd.sing.ne.jp/</link> <dc:date>2018-10-23T17:27:13+0900</dc:date> <items> <rdf:Seq> <rdf:li rdf:resource="https://freebsd.sing.ne.jp/00/"/> </rdf:Seq> </items> </channel> <item rdf:about="https://freebsd.sing.ne.jp/00/"> <dc:format>text/html</dc:format> <dc:date>2018-10-23T08:27:13+0900</dc:date> <dc:creator>Show.Kit</dc:creator> <title>共通事項</title> <link>https://freebsd.sing.ne.jp/00/</link> <description>ももも</description> </item> </rdf:RDF>
<?xml version="1.0" encoding="UTF-8"?> <!-- generator="FeedCreator 1.8" --> <rss version="2.0"> <channel xmlns:g="http://base.google.com/ns/1.0"> <title>FreeBSD あれこれ</title> <description>FreeBSD をはじめ OS・サーバ・アプリケーション等の紹介サイト。</description> <link>https://freebsd.sing.ne.jp/</link> <lastBuildDate>Tue, 23 Oct 2018 17:27:13 +0000</lastBuildDate> <generator>FeedCreator 1.8</generator> <item> <title>共通事項</title> <link>https://freebsd.sing.ne.jp/00/</link> <description>ももも</description> <pubDate>Tue, 23 Oct 2018 08:27:13 +0000</pubDate> </item> </channel> </rss>
<?xml version="1.0" encoding="utf-8"?> <!-- generator="FeedCreator 1.8" --> <feed xmlns="http://www.w3.org/2005/Atom"> <title>FreeBSD あれこれ</title> <subtitle>FreeBSD をはじめ OS・サーバ・アプリケーション等の紹介サイト。</subtitle> <link rel="alternate" type="text/html" href="https://freebsd.sing.ne.jp/"/> <id>https://freebsd.sing.ne.jp/</id> <updated>2018-10-23T17:27:13+0900</updated> <generator>FeedCreator 1.8 (info@mypapit.net)</generator> <link rel="self" type="application/atom+xml" href="" /> <entry> <title>共通事項</title> <link rel="alternate" type="text/html" href="https://freebsd.sing.ne.jp/00/"/> <published>2018-10-23T08:27:13+0900</published> <updated>2018-10-23T08:27:13+0900</updated> <id>https://freebsd.sing.ne.jp/00/</id> <author> <name>Show.Kit</name> </author> <content>ももも</content> <summary>ももも</summary> </entry> </feed>
なるほど、ある程度理解できました。