channel->title; $channel['link'] = $xml->channel->link; $channel['description'] = $xml->channel->description; $channel['pubDate'] = $xml->channel->pubDate; $channel['timestamp'] = strtotime($xml->channel->pubDate); //echo '

' . $channel['title'] . '

'; echo '

' . $channel['title'].'

'.PHP_EOL; $cpt=0; foreach ($xml->channel->item as $item) { $article = array(); $article['title'] = $item->title; $article['link'] = $item->link; $orgStrings = array('?xtor=RSS-13'); $newStrings = array(''); $article['link'] = str_replace($orgStrings, $newStrings, $article['link']); $article['pubDate'] = $item->pubDate; $article['timestamp'] = strtotime($item->pubDate); $article['description'] = $item->description; //$article['image'] = $item->enclosure['url']; $articles[$cpt] = $article; echo '
'.PHP_EOL; //echo '

'.PHP_EOL; echo '  '.PHP_EOL; echo ' '; echo $article['title'].'  '.PHP_EOL; echo '
'.PHP_EOL; $cpt++; if( $cpt > $NEWS_RSS_MAX_ITEMS ) { break; } } } echo ''; echo '
'.PHP_EOL; echo '
'; echo '
'.PHP_EOL; $cpt=0; foreach ($articles as $article ) { $cpt_prev=$cpt-1; $cpt_next=$cpt+1; warning($article['link']); echo PHP_EOL.PHP_EOL."".PHP_EOL; echo "
\n"; echo "
\n"; $article_content = file_get_contents($article['link']); $article_content_utf8 = mb_convert_encoding($article_content, 'HTML-ENTITIES', "UTF-8"); $article_content = $article_content_utf8; $doc = new DOMDocument(); $doc->preserveWhiteSpace = false; $doc->formatOutput = true; $libxml_previous_state = libxml_use_internal_errors(true); $doc->loadHTML($article_content); libxml_clear_errors(); libxml_use_internal_errors($libxml_previous_state); $articles = $doc->getElementsByTagName('div'); $article_only = ""; foreach ( $articles as $node) { $classname = $node->getAttribute('id'); if($classname == 'ObsArticle-body' ) { $article_only = DOMinnerHTML($node); break; } } if( 0 == strlen($article_only)) { $article_only = "Extraction failed"; } $metas = $doc->getElementsByTagName('meta'); $chapo = ""; foreach ( $metas as $node) { $classname = $node->getAttribute('property'); if(0==strcmp($classname,'og:description') ) { $chapo = $node->getAttribute('content'); }else if(0==strcmp($classname,'og:image') ) { $article['image'] = $node->getAttribute('content'); } } $orgStrings = array(' href="/'); $newStrings = array(' href="https://www.nouvelobs.com/'); $article_only = str_replace($orgStrings, $newStrings, $article_only); $temp = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $article_only); $article_only = $temp; $temp = preg_replace('/\s\s+/', ' ', $article_only); $article_only = $temp; $article_only = re_remove($article_only, '/
'.PHP_EOL; $cpt++; if( $cpt > $NEWS_RSS_MAX_ITEMS ) { break; } } ?>