這可能會或可能不會幫助你,但是這是我用生成的Atom feed代碼:
<?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(dirname(__file__)));
define('HOST', 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']));
function publishAtom() {
/*
My data entities had these fields:
- title
- category
- permalink (a URL-safe version of the title)
- timestamp
- lastupdated
- abstract
You'll need to adjust the code below to match your entities.
*/
# get the data
$rows = //<<insert your data-gathering-code here>> -> needs to be an array of your entities;
$feed_title = "Atom Feed";
$feed_subtitle = "Get all our newest entries when you subscribe to the feed.";
$site_domain = "http://yourdomain.com";
$author_name = "Your Name";
$author_email = "[email protected]";
$feed = '<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>' . $feed_title . '</title>
<subtitle>' . $feed_subtitle . '</subtitle>
<link href="' . $site_domain . '/atom.xml" rel="self" />
<link href="' . $site_domain . '" />
<updated>' . date('c') . '</updated>
<author>
<name>' . $author_name . '</name>
<email>' . $author_email . '</email>
</author>
<id>tag:' . str_replace("http://", '', $site_domain) . ',2012:feed</id>';
# Get the entries
foreach($rows as $row) {
$feed .= '<entry>
<title>' . $row->title . '</title>
<link href="' . strtolower($site_domain . DS . $row->category . DS . $row->permalink) . '" />';
$date= date('Y-m-d', strtotime($row->timestamp));
$uuid = str_replace("http://", '', $site_domain) . ',' . $date . ':' . $row->permalink;
$feed .= '<id>tag:' . $uuid . '</id>';
if(isset($row->lastupdated)) {
$feed .= '<updated>' . date('c', strtotime($row->lastupdated)) . '</updated>';
}
else {
$feed .= '<updated>' . date('c', strtotime($row->timestamp)) . '</updated>';
}
$feed .= '<summary>Entry for ' . $date . '</summary>
<content type="xhtml" xml:lang="en">
<div xmlns="http://www.w3.org/1999/xhtml">' . $row->abstract . '</div>
</content>
</entry>';
}
$feed .= "</feed>";
$path = ROOT . DS . "atom.xml";
$filenum=fopen($path, "w");
fwrite($filenum, $feed);
fclose($filenum);
}
}
# call this function wherever is relevent for you
publishAtom();
?>
它應該給你一個關於如何手動完成的想法。 HTH。
首先,您需要設置內容類型爲text/xml。然後,不是輸出HTML,而是根據RSS原子規範輸出XML格式。 – 2012-07-15 08:48:18