Home>

Currently get RSS feeds from multiple sites,
"Sorted by new arrival order" ;, but displays
New articles like 1-5, 6-10, 11-15, etc.
I want to display 5 blocks separately.

Finally, implement a "More" button,
I want to be able to browse 5 new articles.

Applicable source code
<? php
// Number of displayed articles
$hyojiNum = 30;
// Feed registration
$data ['feedurl'] [] = 'http://feeds.feedburner.com/design-develop/BZkU';
$data ['feedurl'] [] = 'http://feeds.feedburner.com/designwork-s/YGrB';
// $data ['feedurl'] [] = '';add as many as you need
$rssList = $data ['feedurl'];
    // simultaneous call
    $rssdataRaw = multiRequest ($rssList);
    for ($n = 0;$n<count ($rssdataRaw);$n ++) {
        // URL setting
        $rssdata = simplexml_load_string ($rssdataRaw [$n], 'SimpleXMLElement', LIBXML_NOCDATA);
        if ($rssdata->channel-&item;$rssdata = $rssdata->channel;
        if ($rssdata->item) {
 $b_title = $rssdata->title;
            foreach ($rssdata->item as $myEntry) {
                $rssDate = $myEntry->pubDate;
                if (! $rssDate) $rssDate = $myEntry->children ("http://purl.org/dc/elements/1.1/")->date;
                date_default_timezone_set ('Asia/Tokyo');
                $myDateGNU = strtotime ($rssDate);
                $myDate = date ('Y/m/d', $myDateGNU);
                $myTitle = mb_strimwidth ($myEntry->title, 0,60, "…", utf8);// Get title
                $myLink = $myEntry->link;// Get link URL
$myContent = $myEntry->children ('http://purl.org/rss/1.0/modules/content/');
$myContent2 = $myContent->encoded;
preg_match ('/<img. *? src? =? [\' "] ([^>] +) [\ '"]. *?>/i', $myContent2, $img_all);
preg_match ('/ http. *? (\. gif | \ .png | \ .jpg | \ .jpeg $| \ .bmp)/i', $img_all [0], $gazo);
$outdata [$myDateGNU] = '<a href = "'. $myLink. '" target = "_ blank">
<div><img src = "'. $gazo [0].'" width = "70"></div>
<div>
<div>'. $myTitle.'</div>
<div>'. $myDate.'</div>
<div>'. $b_title.'</div>
</div>
</a>';
            }
        }
    }
    //sort
    krsort ($outdata);
$nn = 0;
$html = '';
//
foreach ($outdata as $outdata) {
    $nn ++;
    $html. = $outdata;
     if ($nn == $hyojiNum) break;
}
// You can display a list with "echo $html" here.
// Simultaneous call function from here
function multiRequest ($data, $options = array ()) {
  // Prepare an array.
  $curly = array ();
  // data to be returned
  $result = array ();
  // Parallel function
  $mh = curl_multi_init ();
  // loop through $data and create curl handles
  // then add them to the multi-handle
  foreach ($data as $id =>$d) {
    $curly [$id] = curl_init ();
    $url = (is_array ($d)&&! empty ($d ['url']))? $d ['url']: $d;
    curl_setopt ($curly [$id], CURLOPT_URL, $url);
    curl_setopt ($curly [$id], CURLOPT_HEADER, 0);
    curl_setopt ($curly [$id], CURLOPT_RETURNTRANSFER, 1);
    // whether there is a post
    if (is_array ($d)) {
      if (! empty ($d ['post'])) {
        curl_setopt ($curly [$id], CURLOPT_POST, 1);
        curl_setopt ($curly [$id], CURLOPT_POSTFIELDS, $d ['post']);
      }
    }
    if (! empty ($options)) {curl_setopt_array ($curly [$id], $options);}
    curl_multi_add_handle ($mh, $curly [$id]);
  }
  $running = null;
// execute handle
  do {
    curl_multi_exec ($mh, $running);
  } while ($running>0);
  foreach ($curly as $id =>$c) {
    $result [$id] = curl_multi_getcontent ($c);
    curl_multi_remove_handle ($mh, $c);
  }
  // close the handle
  curl_multi_close ($mh);
  return $result;
}
?>

[Source] http://idea-cloud.com/funky/diary/curl_multi.html

Supplement

Originally, the number of acquisitions was divided according to the following description,
I can't transfer it to the above source.
Thanks for your knowledge.

$maxitems = $rss->get_item_quantity (15);
$rss_items = $rss->get_items (0, 5);
$rss_items2 = $rss->get_items (6, 5);
$rss_items3 = $rss->get_items (11, 5);
  • Answer # 1

    Since it was unknown how to display RSS feeds in multiple blocks,
    Use jQuery to display n articles.

    Reference articles are as follows.
    https://StackOverflow.com/questions/92715