rss 뉴스제목글을 지정된 언론사별로 가져와서 홈페이지에 출력하려고 합니다.
아래 코드처럼 짜집기를 했는데
일단, 언론사별 rss 뉴스제목를 가져와서 출력이 되는거 까지는 이상이 없습니다
문제는...
아래 코드처럼 하면 ... 있는대로 다 가져오다 보니 약 100여개의 '뉴스제목'이 출력 되어버립니다.
홈페이지에는 '최신시간'순으로 or '기타'기준으로...
언론사구분없이 통틀어서 10여개 정도의 rss 뉴스제목만 홈페이지에 출력하고 싶습니다.
코드의 어느부분을 어떻게 손봐야 할런지요...??
도움글을 좀 부탁드립니다.
---------- 코드참고 ------------------------
$news = array(
"sports" => array("스포츠서울","http://www.sportsseoul.com/rss/rss.asp?cp_flag=1&cat_flag=1"),
"ohmynews" => array("오마이뉴스","http://rss.ohmynews.com/rss/ohmynews.xml"),
"chosun" => array("조선일보","http://newsplus.chosun.com/hitdata/xml/index/index.xml"),
"hani" => array("한겨레신문","http://www.hani.co.kr/rss/newsrank/"),
"kbench" => array("케이벤치","http://rss.kbench.com/news.xml"),
"YTN뉴스" => array("YTN","http://www.yonhapnews.co.kr/RSS/sokbo.xml")
);
"sports" => array("스포츠서울","http://www.sportsseoul.com/rss/rss.asp?cp_flag=1&cat_flag=1"),
"ohmynews" => array("오마이뉴스","http://rss.ohmynews.com/rss/ohmynews.xml"),
"chosun" => array("조선일보","http://newsplus.chosun.com/hitdata/xml/index/index.xml"),
"hani" => array("한겨레신문","http://www.hani.co.kr/rss/newsrank/"),
"kbench" => array("케이벤치","http://rss.kbench.com/news.xml"),
"YTN뉴스" => array("YTN","http://www.yonhapnews.co.kr/RSS/sokbo.xml")
);
$ns = $HTTP_GET_VARS["ns"];
if(empty($ns)){ $ns = array_keys($news); }
if(empty($ns)){ $ns = array_keys($news); }
$newsList = array();
while (list($key, $value) = each ($news)) {
$url = $value[1];
$rss = new RSSReader($url,true,60,$DOCUMENT_ROOT."/newsmowa/cache");
$response = $rss->Read();
while (list($key, $value) = each ($news)) {
$url = $value[1];
$rss = new RSSReader($url,true,60,$DOCUMENT_ROOT."/newsmowa/cache");
$response = $rss->Read();
foreach($rss->getItems() as $item){
if(isChoice($key)){
if(isset($item["dc:date"])) $item["pubdate"] = $item["dc:date"];
//array_push($newsList,array($value[0],$item["title"],$item["link"],$item["description"],$item["pubdate"]));
array_push($newsList,
array(
NAME => $value[0],
TITLE => $item["title"],
LINK => $item["link"],
DESCRIPTION => $item["description"],
PUBDATE => $item["pubdate"],
TOPUBDATE => _Topubdate($item["pubdate"]),
IDXPUBDATE => _Topubdate($item["pubdate"],"YmdHis")
)
);
}
}
if(isset($item["dc:date"])) $item["pubdate"] = $item["dc:date"];
//array_push($newsList,array($value[0],$item["title"],$item["link"],$item["description"],$item["pubdate"]));
array_push($newsList,
array(
NAME => $value[0],
TITLE => $item["title"],
LINK => $item["link"],
DESCRIPTION => $item["description"],
PUBDATE => $item["pubdate"],
TOPUBDATE => _Topubdate($item["pubdate"]),
IDXPUBDATE => _Topubdate($item["pubdate"],"YmdHis")
)
);
}
}
$rss->free();
unset($rss);
}
unset($rss);
}
usort($newsList,"cmp");
echo "<html><head><title>뉴스모와</title>\n";
echo "<style><!-- BODY,TD,SELECT { FONT: 9pt Arial; LINE-HEIGHT: 17px;} //--></style>\n";
echo "<body>";
echo "<form>";
echo "<table width=100% border=1>\n";
echo "<tr><td>\n";
echo "<style><!-- BODY,TD,SELECT { FONT: 9pt Arial; LINE-HEIGHT: 17px;} //--></style>\n";
echo "<body>";
echo "<form>";
echo "<table width=100% border=1>\n";
echo "<tr><td>\n";
foreach($news as $key => $value) {
$checked = isChoice($key)? "checked":"";
echo "<input type=checkbox name=ns[] value=$key $checked> $value[0]\n";
}
echo "<input type=submit value=\"조회\"></td></tr>\n";
echo "</table>";
echo "</form>";
echo "</table>";
echo "</form>";
echo "<table width=100% border=0>\n";
echo "<tr><td align=center>뉴스제목</td><td align=center>출처</td><td align=center>발행일</td></tr>\n";
foreach($newsList as $list){
printf("<tr><td><a href=\"%s\" target=_blank>%s</td><td align=center>%s</td><td align=center>%s</td></tr>\n",
$list[LINK],$list[TITLE],$list[NAME],$list[TOPUBDATE]);
}
echo "</table>";
echo "<tr><td align=center>뉴스제목</td><td align=center>출처</td><td align=center>발행일</td></tr>\n";
foreach($newsList as $list){
printf("<tr><td><a href=\"%s\" target=_blank>%s</td><td align=center>%s</td><td align=center>%s</td></tr>\n",
$list[LINK],$list[TITLE],$list[NAME],$list[TOPUBDATE]);
}
echo "</table>";
echo "</body></html>\n";
?>
?>
댓글 1개
영리한바부
13년 전
이미 처리 하셨는지 모르겠는데 혹시 해결하지 못하셨다면
참고 해서 수정해보십시요
// xml결과값을 모두 배열에 저장구현
// 다중배열 정렬
foreach (뉴스배열 as $key => $row) {
$sort[$key] = $row[' IDXPUBDATE'];
}
array_multisort($sort, SORT_ASC, 뉴스배열); // SORT_ASC , SORT_DESC
// 원하는 수만큼 뉴스 출력구현
http://php.net/manual/en/function.array-multisort.php
참고 해서 수정해보십시요
// xml결과값을 모두 배열에 저장구현
// 다중배열 정렬
foreach (뉴스배열 as $key => $row) {
$sort[$key] = $row[' IDXPUBDATE'];
}
array_multisort($sort, SORT_ASC, 뉴스배열); // SORT_ASC , SORT_DESC
// 원하는 수만큼 뉴스 출력구현
http://php.net/manual/en/function.array-multisort.php
게시판 목록
프로그램
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 5330 | 13년 전 | 774 | ||
| 5329 | 13년 전 | 711 | ||
| 5328 | 13년 전 | 642 | ||
| 5327 | 13년 전 | 886 | ||
| 5326 |
downmix
|
13년 전 | 1123 | |
| 5325 |
techer
|
13년 전 | 3149 | |
| 5324 |
techer
|
13년 전 | 978 | |
| 5323 | 13년 전 | 1187 | ||
| 5322 |
김준수사랑
|
13년 전 | 897 | |
| 5321 |
다케미카코
|
13년 전 | 756 | |
| 5320 |
|
13년 전 | 999 | |
| 5319 |
한번잘해보자
|
13년 전 | 1011 | |
| 5318 |
|
13년 전 | 1275 | |
| 5317 |
techer
|
13년 전 | 2707 | |
| 5316 |
techer
|
13년 전 | 3149 | |
| 5315 | 13년 전 | 1180 | ||
| 5314 |
티즈코리아
|
13년 전 | 1231 | |
| 5313 | 13년 전 | 712 | ||
| 5312 |
|
13년 전 | 1877 | |
| 5311 |
innis
|
13년 전 | 775 | |
| 5310 | 13년 전 | 864 | ||
| 5309 |
changho
|
13년 전 | 663 | |
| 5308 |
|
13년 전 | 1368 | |
| 5307 |
|
13년 전 | 804 | |
| 5306 | 13년 전 | 1189 | ||
| 5305 |
세상속으로
|
13년 전 | 1169 | |
| 5304 | 13년 전 | 672 | ||
| 5303 | 13년 전 | 2264 | ||
| 5302 | 13년 전 | 1400 | ||
| 5301 | 13년 전 | 1113 | ||
| 5300 |
프로프리랜서
|
13년 전 | 1093 | |
| 5299 | 13년 전 | 876 | ||
| 5298 | 13년 전 | 685 | ||
| 5297 |
나랑사귈래
|
13년 전 | 612 | |
| 5296 | 13년 전 | 1340 | ||
| 5295 | 13년 전 | 1121 | ||
| 5294 | 13년 전 | 731 | ||
| 5293 |
|
13년 전 | 5824 | |
| 5292 |
|
13년 전 | 794 | |
| 5291 | 13년 전 | 623 | ||
| 5290 | 13년 전 | 559 | ||
| 5289 | 13년 전 | 657 | ||
| 5288 | 13년 전 | 1174 | ||
| 5287 | 13년 전 | 766 | ||
| 5286 | 13년 전 | 980 | ||
| 5285 | 13년 전 | 1327 | ||
| 5284 |
미스홍당무
|
13년 전 | 864 | |
| 5283 |
basketball
|
13년 전 | 1767 | |
| 5282 | 13년 전 | 797 | ||
| 5281 |
|
13년 전 | 811 | |
| 5280 | 13년 전 | 1218 | ||
| 5279 | 13년 전 | 1389 | ||
| 5278 |
크라이스트
|
13년 전 | 2055 | |
| 5277 |
|
13년 전 | 734 | |
| 5276 |
그누보드환자이송
|
13년 전 | 791 | |
| 5275 | 13년 전 | 705 | ||
| 5274 | 13년 전 | 1377 | ||
| 5273 | 13년 전 | 2007 | ||
| 5272 | 13년 전 | 1121 | ||
| 5271 | 13년 전 | 1436 | ||
| 5270 | 13년 전 | 809 | ||
| 5269 | 13년 전 | 533 | ||
| 5268 | 13년 전 | 670 | ||
| 5267 | 13년 전 | 1193 | ||
| 5266 | 13년 전 | 1860 | ||
| 5265 | 13년 전 | 1631 | ||
| 5264 |
크라이스트
|
13년 전 | 1213 | |
| 5263 |
|
13년 전 | 1266 | |
| 5262 |
제이티37
|
13년 전 | 588 | |
| 5261 |
|
13년 전 | 784 | |
| 5260 |
quenya
|
13년 전 | 2076 | |
| 5259 | 13년 전 | 712 | ||
| 5258 | 13년 전 | 735 | ||
| 5257 |
크라이스트
|
13년 전 | 4600 | |
| 5256 | 13년 전 | 1258 | ||
| 5255 | 13년 전 | 3269 | ||
| 5254 |
|
13년 전 | 712 | |
| 5253 | 13년 전 | 773 | ||
| 5252 | 13년 전 | 774 | ||
| 5251 | 13년 전 | 727 | ||
| 5250 |
dudn1114
|
13년 전 | 1293 | |
| 5249 | 13년 전 | 673 | ||
| 5248 | 13년 전 | 743 | ||
| 5247 | 13년 전 | 2085 | ||
| 5246 | 13년 전 | 511 | ||
| 5245 | 13년 전 | 2201 | ||
| 5244 | 13년 전 | 1463 | ||
| 5243 |
|
13년 전 | 976 | |
| 5242 | 13년 전 | 770 | ||
| 5241 | 13년 전 | 1852 | ||
| 5240 |
|
13년 전 | 510 | |
| 5239 | 13년 전 | 1039 | ||
| 5238 | 13년 전 | 1226 | ||
| 5237 | 13년 전 | 1122 | ||
| 5236 | 13년 전 | 591 | ||
| 5235 |
|
13년 전 | 771 | |
| 5234 |
뭐먹고살지ㅠ
|
13년 전 | 1033 | |
| 5233 | 13년 전 | 3598 | ||
| 5232 | 13년 전 | 3142 | ||
| 5231 | 13년 전 | 3732 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기