Buenas!!! Intento hacer una script para sacar la informacion RSS de alguna pagina usando el DOMDocument. No encuentro la solucion al error. De paso me podeis decir si lo hago esta bien encamindo... es que nunca he tocado las rss...
PD: el codigo no esta todo comentado... aun esta en desarollo XDXDXD
Código php:
Ver original<?php
class RSS_PHP
{
var $xml;
var $load_dom;
private $channel_atr = array(); //tags del canal. var $channel_all = array(); //toda la informacio que hay en el canal. var $channel; //
var $descript_nom = array(); //informacion sobre el contenido del tag <description> de cda item. var $descript; //
var $title_nom = array(); //informacion sobre el contenido del tag <title> de cda item. var $title; //
var $link_nom = array(); //informacion sobre el contenido del tag <link> de cda item. var $link; //
private $item_atr = array(); //tags del item. private $item_all = array(); //toda la informacion que hay en item. var $item; //
function RSS_PHP()
{
//tags por defecto para channel.
$this -> channel_atr = array("title","link","description","language","pubDate", "lastBuildDate","docs","generator","managingEditor","webMaster");
//tags por defecto para item
$this -> item_atr = array("title","link","description","pubDate","guid"); }
function getRss($xml)
{
//comprueba que exite algo en la variable $xml.
//llama a la funcion de carga del xml
if(empty($xml)){return(False);} else
{
$this->xml = $xml;
return($this->load_func());
}
}
function load_func()
{
//carga el xml.
$this->load_dom = new DOMDocument;
$this->load_dom->load($this->xml);
//comprueba que se ha cargado correctamete.
if(!$this->load_dom){return(False);}
else{return(True);}
}
function getChannel()
{
$this->channel = $this->load_dom->getElementsByTagName("channel");
}
function getItem()
{
$this->item = $this->load_dom->getElementsByTagName("item");
}
function getChannelInfo($info)
{
if(empty($info)){$info = $this->channel_atr;} foreach($this->channel as $canal)
{
for($ind = 0;$ind < count($info);$ind++) {
$information = $canal->getElementsByTagName($info[$ind]);
if(isset($information->item(0)->nodeValue)) {
$this->channel_all[$info[$ind]] = $information->item(0)->nodeValue;
}
}
}
return($this->channel_all);
}
function getItemInfo($info)
{
if(empty($info)){$info = $this->item_atr;} if(!isset($this->item)){$this->getItem();} foreach($this->item as $item)
{
for($ind = 0;$ind < count($this->item);$ind++) {
for($ind2 = 0;$ind2 < count($info);$ind2++) {
$tag = $item->getElemetsByTagName($info[$ind2]); //error aqui!!!! <------>
if(isset($tag->item(0)->nodeValue)) {
$this->item_all[$ind][$info[$ind2]] = $tag->item(0)->nodeValue;
}
}
}
}
return($this->item_all);
}
function getTitle()
{
if(!isset($this->item)){$this->getItem();} $ind = 0;
foreach($this->item as $this->title)
{
$title = $this->title->getElementsByTagName("title");
$this->title_nom[$ind] = $title->item(0)->nodeValue;
$ind++;
}
if(!empty($this->title_nom)){return($this->title_nom);} else{return(False);}
}
function getDescript()
{
if(!isset($this->item)){$this->getItem();} $ind = 0;
foreach($this->item as $this->descript)
{
$descript = $this->descript->getElementsByTagName("description");
$this->descript_nom[$ind] = $descript->item(0)->nodeValue;
$ind++;
}
if(!empty($this->descript_nom)){return($this->descript_nom);} else{return(False);}
}
}
/*$rss = new RSS_PHP;
$rss->getRss("http://www.amposta.cat/rss.asp");
$item = $rss->getItemInfo("");
print_r($item);*/
?>