<?php
function lecteur_rss($file,$option=false) {

	$max= (isset($option['max'])) ? $option['max'] : 5;
	$leng= (isset($option['leng'])) ? $option['leng'] : 100;
	$leng_titre= (isset($option['leng_titre'])) ? $option['leng_titre'] : 30;
	$format_item= (isset($option['format_item'])) ? $option['format_item'] : '<h3><span> {date} </span> <a href="{link}" title="{title}"> {titre} </a></h3> <p> {text}</p>';


	print "<ul>\n";
	if (!function_exists('unhtmlentities')){
	 function unhtmlentities($chaineHtml) {
	         $tmp = get_html_translation_table(HTML_ENTITIES);
	         $tmp = array_flip ($tmp);
	         $chaineTmp = strtr ($chaineHtml, $tmp);
	         return $chaineTmp;
	 }
	}
	## affichage flux
	$raw=@file_get_contents($file);
	if ($raw){
		if (eregi("<item(.*)</item>",$raw,$rawitems)){
			$items=explode("<item",$rawitems[0]);
			$nb=count($items);
			$maximun=(($nb-1)<$max) ? ($nb-1) : $max;
			for ($i=0;$i<$maximun;$i++){
				eregi("<pub_dat>(.*)</pub_dat>",$items[$i+1],$pub_dat);
				eregi("<title>(.*)</title>",$items[$i+1],$title);
				eregi("<description>(.*)</description>",$items[$i+1],$description);
				eregi("<link>(.*)</link>",$items[$i+1],$link);

				$date=date("d/m",strtotime($pub_dat[1]." +0200" ));
				$htmlentitie= (isset($option['htmlentities'])) ? unhtmlentities($description[1]) : $description[1];
				$descr= (isset($option['utf8'])) ? utf8_decode($htmlentitie) : $htmlentitie;
				print str_replace(array('{date}','{link}','{title}','{titre}','{text}'),array($date,$link[1],$title[1],substr($title[1],0,$leng_titre),substr($descr,0,$leng)),$format_item.'...');
			}
		}else print "<li>&nbsp;</li>\n";
	}
	else print "<li>&nbsp;</li>\n";
	print "</ul>\n";
 }
?>