Salut , voila j ai récupérer un code php qui me permet d’afficher les flux xml et rss avec enclosure .
il fonctionne très bien mais avec certain flux j ai une erreur ( voir erreur ci dessous )
Warning: PodcastItem::__construct() [podcastitem.--construct]: Node no longer exists in /home/servermick/www/test/Podcast.php on line 95
Warning: PodcastItem::__construct() [podcastitem.--construct]: Node no longer exists in /home/servermick/www/test/Podcast.php on line 96
Warning: PodcastItem::__construct() [podcastitem.--construct]: Node no longer exists in /home/servermick/www/test/Podcast.php on line 97
Voici mon code php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
//
// $Id$
class Podcast {
private $feed_url;
private $items;
private $channel;
function __construct()
{
$this->channel = array();
$this->items = array();
}
/**
* Gets the feed and parses it
*/
function parseFeed($url)
{
$this->feed_url = $url;
$file = file_get_contents($url);
$xml_parser = simplexml_load_string($file);
$this->channel = array( // Maps SimpleXML elements into the object
'title'=>(string) $xml_parser->channel->title,
'link'=> (string) $xml_parser->channel->link,
'description'=>(string) $xml_parser->channel->description,
'pubDate'=>(string) $xml_parser->channel->pubDate
);
foreach ($xml_parser->channel->children()->item as $item)
{ // pushes on PodcastItem objects into the items array for each <item> tag
$this->items[] = new PodcastItem($item);
}
unset($xml_parser);
return true;
}
function getChannelInfo()
{
return $this->channel;
}
function getItems()
{
return $this->items;
}
/**
Resets the object ready to parse another feed.
*/
function reset()
{
$this->__construct();
}
function getHash()
{
return md5(serialize($this));
}
}
class PodcastItem {
public $metadata;
public $enclosure;
/**
Converts from SimpleXMLElement to a normal user object
This means you can serialise/cache it if you wish
*/
function __construct($xml_obj)
{
$this->metadata = array(
'title'=> (string) $xml_obj->title,
'description'=> (string) $xml_obj->description,
'link'=> (string) $xml_obj->link,
'guid'=> (string) $xml_obj->guid,
'pubDate'=> (string) $xml_obj->pubDate,
);
$enc_tmp = $xml_obj->enclosure->attributes();
$this->enclosure = array(
'url'=> (string) $enc_tmp->url,
'length'=> (string) $enc_tmp->length,
'type'=> (string) $enc_tmp->type,
);
}
}
?>
Edité le 12/03/2010 à 18:22