-1
我有這個代碼的問題,它創建一個index.html文件鏈接從給定的RSS鏈接。我試圖在index.html結尾文件中生成每個rss源的列,並且列將按每行3個進行分組。所以在腳本處理rss鏈接數組的第三個鏈接之後,我想在新行中重複這個過程,但是我沒有得到正確的排序,我想要計算或插入結束和打開標記。每3 colums的數據生成一個新的div行
<?php
require_once('magpierss/rss_fetch.inc'); // RSS library to fetch RSS news
$rss_links = array(
'NYT World' => 'http://rss.nytimes.com/services/xml/rss/nyt/World.xml',
'NYT US' => 'http://rss.nytimes.com/services/xml/rss/nyt/US.xml',
'NYT Business' => 'http://rss.nytimes.com/services/xml/rss/nyt/Business.xml',
'NYT Technology' => 'http://rss.nytimes.com/services/xml/rss/nyt/Technology.xml',
'NYT Sports' => 'http://rss.nytimes.com/services/xml/rss/nyt/Sports.xml'
);
$limit = 10; // Notice limit per RSS
$count = 0;
if ($limit) {
$per_column = floor((count($rss_links) * $limit)/3);
} else {
foreach ($rss_links as $url) {
$rss = fetch_rss($url);
$count += count($rss->items);
}
$per_column = floor($count/3);
}
$html = '<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>RSS GENERATE</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/bootstrap.css">
</head>
<body>
<div class="container">
<div class="row">';
$count = 0;
$rowCount = 0;
// print_r($rss_links);
// break;
foreach ($rss_links as $url) {
if ($rowCount % 3 === 0) {
$html .= '</div><div class="row">';
}
$rss = fetch_rss($url);
if ($count == 0) {
$html .= '<div class="col-xs-6 col-sm-4">
<h1>'.$rss->channel['title'].'</h1>
<ul class="list-unstyled">';
}
// $html .= '<h1>'.$rss->channel['title'].'</h1>';
$c = 0;
foreach ($rss->items as $item) {
$html .= '<li><a href="' . $item['link'] . '">' . $item['title'] . $count .'</a></li>';
$count++; $c++;
if ($limit && $limit == $c) {
continue(2);
}
if ($count == ($per_column + 1)) {
$count = 0;
$html .= '</ul></div><div class="col-xs-6 col-sm-4">
<ul class="list-unstyled">';
}
}
$rowCount++;
}
$html .= '</ul>
</div>
</div>
</div>
</body>
</html>';
file_put_contents('index.html', $html);
?>
你得到了什麼輸出?顯示輸出。同時舉一個你想要的輸出的例子。 – user2936213