restituisce un array dai feed rss di un blog con i dati di creazione, modifica, autore, tag etc..
poi al bisogno sarà necessario customizzarla ..
class reader
{
function reader()
{
$this->__construct();
}
function __construct()
{
$this->tag_selection = array('published','updated','title','content','category','name');
}
function filter($value)
{
if(function_exist('iconv'))
$value = iconv('UTF-8', 'ISO-8859-1//TRANSLIT', $value);
return $value;
}
function get($fn)
{
var_dump($this->tag_selection); // Debug
// Open and load RSS file
if ($f = fopen($fn, 'r')) {
$rss_content = '';
while (!feof($f)){
$rss_content .= fgets($f, 4096);
}
fclose($f);
}
// Prelevo tutti i post inseriti
preg_match_all("'(.*?) 'si", $rss_content, $items);
$rss_items = $items[2];
$i = 0; $feed = array();
foreach($rss_items as $rss_item)
{
reset($this->tag_selection);
foreach($this->tag_selection as $itemtag)
{
if($itemtag == 'category')
preg_match("'term=[\'\"](.*?)[\'\"]'si", $rss_item,$tmp);
else
preg_match("'<$itemtag.*?>(.*?)'si", $rss_item,$tmp);
if ($tmp[1] != '') $feed[$i][$itemtag] = $this->filter($tmp[1]);
}
$i++;
}
return $feed;
}
}
$rss = new reader();
$feed = $rss->get('http://ringomato.blogspot.com/feeds/posts/default');
No comments:
Post a Comment