2012-07-12 5 views
-1

연관 배열에로드 된 각 URL에서 여러 피드를 출력하는 간단한 피드가 있습니다.기존 어레이를 가져 와서 값으로 제동

이 연관 배열은 값을 사용하여 배열을 사전 순으로 정렬하는 데 사용됩니다.

동일한 값 정렬을 사용하고 동일한 URL 또는 값을 가진 모든 배열을 유지하려고하므로 foreach 루프가 실행될 때 해당 URL의 모든 피드를 포함하는 URL 당 하나의 div를 얻습니다

<?php 

require_once('php/autoloader.php'); 


$feed = new SimplePie(); // Create a new instance of SimplePie 
// Load the feeds 
$urls = array(
    'http://abcfamily.go.com/service/feed?id=774372' => 'abc', 
    'http://animal.discovery.com/news/news.rss' => 'animalplanet', 
    'http://www.insideaolvideo.com/rss.xml' => 'aolvideo', 
    'http://feeds.bbci.co.uk/news/world/rss.xml' => 'bbcwn', 
    'http://www.bing.com' => 'bing', 
    'http://www.bravotv.com' => 'bravo', 
    'http://www.cartoonnetwork.com' => 'cartoonnetwork', 
    'http://feeds.cbsnews.com/CBSNewsMain?format=xml' => 'cbsnews', 
    'http://www.clicker.com/' => 'clicker', 
    'http://feeds.feedburner.com/cnet/NnTv?tag=contentBody.1' => 'cnet', 
    'http://www.comedycentral.com/' => 'comedycentral', 
    'http://www.crackle.com/' => 'crackle', 
    'http://www.cwtv.com/feed/episodes/xml' => 'cw', 
    'http://disney.go.com/disneyxd/' => 'disneyxd', 
    'http://www.engadget.com/rss.xml' => 'engadget', 
    'http://syndication.eonline.com/syndication/feeds/rssfeeds/video/index.xml' => 'eonline', 
    'http://sports.espn.go.com/espn/rss/news' => 'espn', 
    'http://facebook.com' => 'facebook', 
    'http://flickr.com/espn/rss/news' => 'flickr', 
    'http://www.fxnetworks.com//home/tonight_rss.php' => 'fxnetworks', 
    'http://www.hgtv.com/' => 'hgtv', 
    'http://www.history.com/this-day-in-history/rss' => 'history', 
    'http://rss.hulu.com/HuluRecentlyAddedVideos?format=xml' => 'hulu', 
    'http://rss.imdb.com/daily/born/' => 'imdb', 
    'http://www.metacafe.com/' => 'metacafe', 
    'http://feeds.feedburner.com/Monkeyseecom-NewestVideos?format=xml' => 'monkeysee', 
    'http://pheedo.msnbc.msn.com/id/18424824/device/rss/' => 'msnbc', 
    'http://www.nationalgeographic.com/' => 'nationalgeographic', 
    'http://dvd.netflix.com/NewReleasesRSS' => 'netflix', 
    'http://feeds.nytimes.com/nyt/rss/HomePage' => 'newyorktimes', 
    'http://www.nick.com/' => 'nickelodeon', 
    'http://www.nickjr.com/' => 'nickjr', 
    'http://www.pandora.com/' => 'pandora', 
    'http://www.pbskids.com/' => 'pbskids', 
    'http://www.photobucket.com/' => 'photobucket', 
    'http://feeds.reuters.com/Reuters/worldNews' => 'reuters', 
    'http://www.revision3.com/' => 'revision3', 
    'http://www.tbs.com/' => 'tbs', 
    'http://www.theverge.com/rss/index.xml' => 'theverge', 
    'http://www.tntdrama.com/' => 'tnt', 
    'http://www.tvland.com/' => 'tvland', 
    'http://www.vimeo.com/' => 'vimeo', 
    'http://www.vudu.com/' => 'vudu', 
    'http://feeds.wired.com/wired/index?format=xml' => 'wired', 
    'http://www.xfinitytv.com/' => 'xfinitytv', 
    'http://www.youtube.com/topic/4qRk91tndwg/most-popular#feed' => 'youtube', 
); 


$feed->set_feed_url(array_keys($urls)); 

$feed->enable_cache(true); 
$feed->set_cache_location('cache'); 
$feed->set_cache_duration(1800); // Set the cache time 
$feed->set_item_limit(0); 
$success = $feed->init(); // Initialize SimplePie 
$feed->handle_content_type(); // Take care of the character encoding 



?> 
<?php require_once("inc/connection.php"); ?> 
<?php require_once("inc/functions.php"); ?> 
<?php include("inc/header.php"); ?> 

<?php 




// Sort it 
$feed_items = array(); 
$items = $feed->get_items(); 
$urls = array_unique($urls); 


foreach ($urls as $url => $image) { 
    $unset = array(); 
    $feed_items[$url] = array(); 


    foreach ($items as $i => $item) { 
    if ($item->get_feed()->feed_url == $url) { 
     $feed_items[$url][] = $item; 
     $unset[] = $i; 

     } 
    } 


    foreach ($unset as $i) { 
    unset($items[$i]); 
    } 
} 


foreach ($feed_items as $feed_url => $items) { 
    if (empty($items)) { 
    ?> 
    <div class="item"><a href="<?php echo $feed_url; ?>"><img src="images/boreds/<?php echo $urls[$feed_url] ?>.png"/><p>Visit <?php echo $urls[$feed_url] ?> now!</p></a></div> 
    <? 
    continue; 
    } 
    $first_item = $items[0]; 
    $feed = $first_item->get_feed(); 
    ?> 

    <?php 

$feedCount = 0; 
    foreach ($items as $item) { 

      $feedCount++; 
    ?> 


     <div class="item"><strong id="amount"><?php echo $feedCount; ?></strong><a href="<?php echo $item->get_permalink(); ?>"><img src="images/boreds/<?php echo $urls[$feed_url] ?>.png"/><p><?php echo $item->get_title(); ?></p></a></div> 
    <?php 
    } 
} 


?> 

<?php require("inc/footer.php"); ?> 
+4

이 매우 심하게 서면 질문이다. 문제를 이해하게해야합니다. 어떤 종류의 형식입니까? 그리고 예상되는 배열 형식은 무엇입니까? 당신은 아무것도 언급하지 않았습니다 – Starx

+0

우리는 우리의 두뇌에 논리를 그릴 수 있도록 코드의 샘플을 보여줄 수 있습니까 :) – PinoyStackOverflower

답변

0

어쩌면 당신이 하나를 사용할 수 있습니다

$feed = new SimplePie(); 
$feed->set_feed_url('http://myfirstfeed','http://mysecondfeed'); 

foreach($feed->get_items() as $k => $item) { 
    echo "<div id='".$k.'">"; 
    echo $item->get_permalink(); 
    echo $title = $item->get_title(); 
    echo $item->get_date('j M Y, g:i a'); 
    echo $item->get_content(); 
    echo "</div>"; 
} 
관련 문제