我想制作一个脚本,从 txt 文件中获取行并为每一行创建新的 rss 提要项。txt 文件会频繁更新新的数据行,因此脚本应该每隔一小时检查一次是否有新行,如果有,则需要制作新的提要项。
我找到了这个 txt2rss 脚本,但我不是很熟练,关于如何修改和使用它的文档很少。http://users.ninthfloor.org/~ashawley/txt2rss/txt2rss.php.html
有人能指出我正确的方向吗?PHP 与 cronjob?或者也许有更简单的方法?
欣赏它
PS:。我也找到了这个脚本。
public static function create($info, $items, $format = 'rss2', $encoding = 'UTF-8')
{
$info += array('title' => 'Generated Feed', 'link' => '', 'generator' => 'KohanaPHP');
$feed = '<?xml version="1.0" encoding="'.$encoding.'"?><rss version="2.0"><channel></channel></rss>';
$feed = simplexml_load_string($feed);
foreach ($info as $name => $value)
{
if ($name === 'image')
{
// Create an image element
$image = $feed->channel->addChild('image');
if ( ! isset($value['link'], $value['url'], $value['title']))
{
throw new Kohana_Exception('Feed images require a link, url, and title');
}
if (strpos($value['link'], '://') === FALSE)
{
// Convert URIs to URLs
$value['link'] = URL::site($value['link'], 'http');
}
if (strpos($value['url'], '://') === FALSE)
{
// Convert URIs to URLs
$value['url'] = URL::site($value['url'], 'http');
}
// Create the image elements
$image->addChild('link', $value['link']);
$image->addChild('url', $value['url']);
$image->addChild('title', $value['title']);
}
else
{
if (($name === 'pubDate' OR $name === 'lastBuildDate') AND (is_int($value) OR ctype_digit($value)))
{
// Convert timestamps to RFC 822 formatted dates
$value = date('r', $value);
}
elseif (($name === 'link' OR $name === 'docs') AND strpos($value, '://') === FALSE)
{
// Convert URIs to URLs
$value = URL::site($value, 'http');
}
// Add the info to the channel
$feed->channel->addChild($name, $value);
}
}
foreach ($items as $item)
{
// Add the item to the channel
$row = $feed->channel->addChild('item');
foreach ($item as $name => $value)
{
if ($name === 'pubDate' AND (is_int($value) OR ctype_digit($value)))
{
// Convert timestamps to RFC 822 formatted dates
$value = date('r', $value);
}
elseif (($name === 'link' OR $name === 'guid') AND strpos($value, '://') === FALSE)
{
// Convert URIs to URLs
$value = URL::site($value, 'http');
}
// Add the info to the row
$row->addChild($name, $value);
}
}
if (function_exists('dom_import_simplexml'))
{
// Convert the feed object to a DOM object
$feed = dom_import_simplexml($feed)->ownerDocument;
// DOM generates more readable XML
$feed->formatOutput = TRUE;
// Export the document as XML
$feed = $feed->saveXML();
}
else
{
// Export the document as XML
$feed = $feed->asXML();
}
return $feed;
}