div.rss { border: 1px solid black; padding: 2px; } div.news { border: 1px solid black; padding:4px; } div.news p { margin:0; padding:0; } div.rss a { color: red; } div.rss a:hover { color: blue; } */ /** * Affiche (version html) un site de nouvelle RSS * @author Yan Morin (yansanmo@iquebec.com) * @param $rssURI L'adresse internet du fil de nouvelles RSS * * Exemple d'utilisation * require_once 'parser.php'; * echoRSS( 'http://yansanmo.no-ip.org:8080/rss.php' ); */ function echoRSS($rssURI) { $simple=''; if (!($fp = fopen($rssURI, "r"))) { die("could not open XML input"); } while (!feof($fp)) { $simple .= fread($fp, 1024); } fclose($fp); $p = xml_parser_create(); xml_parse_into_struct($p, $simple, $vals, $index); xml_parser_free($p); echoln ('
'); // le code pour afficher titre du rss pourrait ressembler à ceci: if ( is_array($index['TITLE']) && count($index['TITLE']) ) { $titleTag = $vals[$index['TITLE'][0]]; if ( $titleTag['level'] == 3 ) { echoln ('

'.$titleTag['value'].'

'); } } $tblItem = $index['ITEM']; if ( !is_array($tblItem) ) return; // écrit rien, s'il n'y a pas d'item foreach ($tblItem as $no ) { if ( $vals[$no]['type'] == 'open' ) { $news = array(); while ( $vals[++$no]['type'] != 'close' ) { $news[$vals[$no]['tag']] = $vals[$no]['value']; } echoItem ( $news ); } } echoln ('
'); } /** * Affiche une nouvelle * @param $item : tableau avec les données * $item['LINK'] : uri (adresse web) * $item['TITLE'] : titre de la nouvelle * $item['DESCRIPTION'] : Description */ function echoItem ( $item ) { echoln ('
'); /* titre */ if ( $item['LINK'] != '' ) { echoln( '

'.$item['TITLE'].'

' ); } else { echoln( '

'.$item['TITLE'].'

' ); } /* description */ if ( $item['DESCRIPTION'] != '' ) { echoln ('

'.$item['DESCRIPTION'].'

'); } echoln ('
'); } /** * Affiche une ligne, avec un retour de ligne */ function echoln($str) { echo $str."\n"; } ?>