The SS/ATOM format is easy to generate. The trouble is that the date format is generated (RSS => pubDate, ATOM => created ).
We found that PHP Date provides the required global variables: (PHP 5.1.1 will support these global variables later)
Echo DATE_RSS; // D, d m y h: I: s O echo DATE_ATOM; // Y-m-d \ TH: I: sP echo date (DATE_RSS ); // Wed, 23 Apr 2008 19:27:19 + 0800 echo date (DATE_ATOM); // 2008-04-23T19: 27: 38 + 08: 00
For MySQL timestamp/datetime format, you can directly use:
Date (DATE_RSS, ($ MYSQL_DATETIME_DATA ));
Currently, the following date global variables are supported:
DATE_ATOM: Atom (example: 2005-08-15T15: 52: 01 + 00: 00) DATE_COOKIE: HTTP Cookies (example: Monday, 15-Aug-05 15:52:01 UTC) DATE_ISO8601: ISO-8601 (example: 2005-08-15T15: 52: 01 + 0000) DATE_RFC822: RFC 822 (example: Mon, 15 Aug 05 15:52:01 + 0000) DATE_RFC850: RFC 850 (example: Monday, 15-Aug-05 15:52:01 UTC) DATE_RFC1036 RFC 1036 (example: mon, 15 Aug 05 15:52:01 + 0000) DATE_RFC1123: RFC 1123 (example: Mon, 15 Aug 2005 15:52:01 + 0000) DATE_RFC2822: RFC 2822 (Mon, 15 Aug 2005 15:52:01 + 0000) DATE_RFC3339: Same as DATE_ATOM DATE_RSS: RSS (Mon, 15 Aug 2005 15:52:01 + 0000) DATE_W3C: World Wide Web consor.pdf (example: 15t15: 52: 01 + 00: 00)
PHP predefined date format
The following constants are defined from PHP 5.1.1 to provide standard date expression methods. They can be used for date format functions.
Echo DATE_RSS; // D, d m y h: I: s O echo DATE_ATOM; // Y-m-d \ TH: I: sP echo date (DATE_RSS ); // Wed, 23 Apr 2008 19:27:19 + 0800 echo date (DATE_ATOM); // 2008-04-23T19: 27: 38 + 08: 00
Although the format is simple, it is not more convenient to use the predefined format in PHP.
Currently, PHP supports the following date formats:
DATE_ATOM: Atom (example: 2005-08-15T15: 52: 01 + 00: 00) DATE_COOKIE: HTTP Cookies (example: Monday, 15-Aug-05 15:52:01 UTC) DATE_ISO8601: ISO-8601 (example: 2005-08-15T15: 52: 01 + 0000) DATE_RFC822: RFC 822 (example: Mon, 15 Aug 05 15:52:01 + 0000) DATE_RFC850: RFC 850 (example: Monday, 15-Aug-05 15:52:01 UTC) DATE_RFC1036 RFC 1036 (example: mon, 15 Aug 05 15:52:01 + 0000) DATE_RFC1123: RFC 1123 (example: Mon, 15 Aug 2005 15:52:01 + 0000) DATE_RFC2822: RFC 2822 (Mon, 15 Aug 2005 15:52:01 + 0000) DATE_RFC3339: Same as DATE_ATOM DATE_RSS: RSS (Mon, 15 Aug 2005 15:52:01 + 0000) DATE_W3C: World Wide Web consor.pdf (example: 15t15: 52: 01 + 00: 00)
Generate rss example
Header ("Content-type: application/xml"); // defines the header to prevent browsers in the chrome kernel from supporting rss subscription, if not, output an xml file/*** to query the database and obtain the data to output rss */$ database = "nameofthedatabase"; $ dbconnect = mysql_pconnect (localhost, dbuser, dbpassword); mysql_select_db ($ database, $ dbconnect); $ query = "select link, headline, description from 'headlines' limit 15"; $ result = mysql_query ($ query, $ dbconnect); while ($ line = mysql_fetch_assoc ($ resu Lt) {$ return [] = $ line;} $ now = date ("D, d m y h: I: s T"); $ output = "<? Xml version = \ "1.0 \" encoding = \ "UTF-8 \"?> <Rss version = \ "2.0 \"> <channel> <title> Shandong Road traffic safety network-$ lanmu </title> <link> http://sdjtaq.cn/rss </link> <description> Latest 100 articles of $ lanmu </description> <pubDate> $ now </pubDate> <lastBuildDate> $ now </lastBuildDate> <docs> http://someurl.com </docs> <managingEditor> 810706080@qq.com </ managingEditor> <webMaster> 810706080@qq.com </webMaster> "; foreach ($ artList as $ line) {$ date = strtotime ($ line ['add _ ti Me ']); // format the database time to the timestamp $ output. = "<item> \ n ". "<title> ". $ line ['title']. "</title> \ n ". "<link> http://sdjtaq.cn/aq_show ". $ line ['id']. ". html </link> \ n ". "<description> <! [CDATA [". $ line ['zhaiao']. "]> </description> \ n ". "<pubDate> ". date ("D, d m y h: I: s O", $ date ). "</pubDate> \ n ". "</item> \ n" ;}$ output. = "</channel> \ n </rss>"; echo $ output;