이 소스에 페이징좀 붙여 주세요. ^^ 정보
이 소스에 페이징좀 붙여 주세요. ^^
본문
아래 소스에 페이징 처리하게끔 수정을 부탁드려도 될까요?
방법을 몰라서 질문드립니다.
<?php
include_once("./_common.php");
include_once("./_common.php");
$html_title = "RSS 뉴스검색";
$g4[title] = $config[cf_title] ." - ". $html_title;
// 헤더화일 불러오기(상단메뉴와 왼쪽메뉴가 이곳에서 불러오겠죠)
include_once("../head.php");
include_once("../_headtail/head_mid.php");
include_once("../head.php");
include_once("../_headtail/head_mid.php");
// rss library 불러오기 (그누보드 lib 디렉토리 화일에 rss.lib.php를 저장해두셔야합니다.)
include_once("../extend/rss.search.lib.php");
include_once("../extend/rss.search.lib.php");
// 회원외 접근금지 기능을 사용하시려면 주석을 제거하세요.
//if (!$member[mb_id]) {
// alert("회원이시라면 로그인 후 이용해 보십시오.", "./bbs/login.php");
// }
// }
// 기본 검색어를 지정합니다. (각자 상황에 맞게) 예를 들어서 월드컵으로 했습니다.
$b_filename = "news_rss_text.txt";
$fp = fopen($b_filename, "r");
$base_word = fread($fp, filesize($b_filename));
fclose($fp);
?>
<!-- 공백 --><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td height="3"></td></tr></table>
<!-- 검색 시작 -->
<form name=fnew method=get style="margin:0px;">
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height=30 width=300>
<b>뉴스검색 : </b>
<input type=hidden id='channel' name='channel' value='<?=$channel?>'>
<input type=text id='channel_query' name='channel_query' value=''>
<input type=submit value='검색'>
</td>
<td>
<a href=<?=$g4[path]?>/new/news_rss.php>네이버</a> /
<form name=fnew method=get style="margin:0px;">
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height=30 width=300>
<b>뉴스검색 : </b>
<input type=hidden id='channel' name='channel' value='<?=$channel?>'>
<input type=text id='channel_query' name='channel_query' value=''>
<input type=submit value='검색'>
</td>
<td>
<a href=<?=$g4[path]?>/new/news_rss.php>네이버</a> /
</td>
<td align=right ><a href="#" onclick="javascript:window.open('<?=$g4[path]?>/new/news_rss_text_del.php', 'del_text', 'left=250, top=250, width=200, height=150');">기본 검색어 변경</a></td>
</tr>
</table>
</form>
<!-- 검색 끝 -->
<td align=right ><a href="#" onclick="javascript:window.open('<?=$g4[path]?>/new/news_rss_text_del.php', 'del_text', 'left=250, top=250, width=200, height=150');">기본 검색어 변경</a></td>
</tr>
</table>
</form>
<!-- 검색 끝 -->
<?
// url_fopen 허용
if (ini_get("allow_url_fopen") == 0) {
ini_set("allow_url_fopen", 1);
}
// 뉴스 검색 RSS 주소입니다.
if ($channel == "") $channel_list = "http://newssearch.naver.com/search.naver?where=rss&query=";
// url_fopen 허용
if (ini_get("allow_url_fopen") == 0) {
ini_set("allow_url_fopen", 1);
}
// 뉴스 검색 RSS 주소입니다.
if ($channel == "") $channel_list = "http://newssearch.naver.com/search.naver?where=rss&query=";
if($channel_query == '') {
$channel_query = "$base_word";
}
// 설정한 채널에서 검색된 뉴스를 읽어온다.
$rss_search_array = rss_search_array($channel_list.$channel_query);
$channel = $rss_search_array['channel']['title'];
$mt_cha =iconv("utf-8","euc-kr","$channel");
$mt_cha =iconv("utf-8","euc-kr","$channel");
?>
<table width="700" border="0" cellspacing="0" cellpadding="0">
<tr><td colspan=3 height=2 bgcolor=#B0ADF5></td></tr>
<tr bgcolor=#F8F8F9 height=30 align=center>
<td ><b><?=$mt_cha?></b> 검색 기사(RSS)</td>
<td width=80>신문사</td>
<td width=100>시간</td>
</tr>
<tr><td colspan=3 height=1 bgcolor=#B0ADF5></td></tr>
<?
<tr><td colspan=3 height=2 bgcolor=#B0ADF5></td></tr>
<tr bgcolor=#F8F8F9 height=30 align=center>
<td ><b><?=$mt_cha?></b> 검색 기사(RSS)</td>
<td width=80>신문사</td>
<td width=100>시간</td>
</tr>
<tr><td colspan=3 height=1 bgcolor=#B0ADF5></td></tr>
<?
if(count($rss_search_array['items']) > 0 ) {
foreach ($rss_search_array['items'] as $item) {
foreach ($rss_search_array['items'] as $item) {
// 뉴스 제목과 뉴스제공 신문사를 euc_kr로 변환한다.
$mtt1 =iconv("utf-8","euc-kr","{$item[title]}");
$mtt2 =iconv("utf-8","euc-kr","{$item['dccreator']}");
$item['dcdate'] = str_replace('+09:00','',$item['dcdate']);
$item['dcdate'] = str_replace('T',' ',$item['dcdate']);
?>
<tr onmouseover="this.style.backgroundColor='#FAF1C2';" onmouseout="this.style.backgroundColor='#FFFFFF';"><td height='26' style='padding-left:10px;'> <li> <a href='<?=$item['link']?>' target='_blank'><?=$mtt1?></a></td><td class=small align=center><?=$mtt2?></td><td class=small align=center><?=$item['dcdate']?></td></tr>
<tr><td colspan='3' height=1 bgcolor=#E7E7E7></td></tr>
<?
<tr onmouseover="this.style.backgroundColor='#FAF1C2';" onmouseout="this.style.backgroundColor='#FFFFFF';"><td height='26' style='padding-left:10px;'> <li> <a href='<?=$item['link']?>' target='_blank'><?=$mtt1?></a></td><td class=small align=center><?=$mtt2?></td><td class=small align=center><?=$item['dcdate']?></td></tr>
<tr><td colspan='3' height=1 bgcolor=#E7E7E7></td></tr>
<?
} //foreach
echo("</table><p><div align=center>위 내용은 RSS를 지원하는 사이트에서 방금 읽어온 내용으로만 구성되어 있습니다.</div>");
} // 검색된 뉴스 갯수 IF
} // 검색된 뉴스 갯수 IF
else {
echo("<tr><td colspan='3' align=center height=100>검색된 뉴스가 없거나, 검색하지 않으셨습니다.</td></tr><tr><td colspan='3' height=1 bgcolor=#B0ADF5></td></tr></table>");
}
echo("<tr><td colspan='3' align=center height=100>검색된 뉴스가 없거나, 검색하지 않으셨습니다.</td></tr><tr><td colspan='3' height=1 bgcolor=#B0ADF5></td></tr></table>");
}
include_once("./_tail.php");
?>
?>
댓글 전체
일부 누락파일 올려주시면 해볼게요.
include_once("../_headtail/head_mid.php"); // ㅋㅋ 이건 몬지 모르겠고용.
include_once("../extend/rss.search.lib.php"); // 호호 이파일 용..
include_once("../_headtail/head_mid.php"); // ㅋㅋ 이건 몬지 모르겠고용.
include_once("../extend/rss.search.lib.php"); // 호호 이파일 용..

파일 여기 있습니다. 부탁드릴께요.
하나는 헤드파일을 나누어 놓은 것입니다.
<?
function rss_search_array($url){
global $g_rss_search_array;
// empty our global array
$g_rss_search_array = array();
// if the URL looks ok
if(preg_match("/^http:\/\/([^\/]+)(.*)$/", $url, $matches)){
$host = $matches[1];
$uri = $matches[2];
$request = "GET $uri HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
$request .= "Connection: close\r\n\r\n";
// open the connection
// 소켓 연결, 최대연결시간 10초로설정
if($http = @fsockopen($host, 80, $errno, $errstr, 10)){
// make the request
fwrite($http, $request);
// read in for max 10 seconds
$timeout = time() + 10;
while(time() < $timeout && !feof($http)) {
$response .= fgets($http, 4096);
}
// split on two newlines
list($header, $xml) = preg_split("/\r?\n\r?\n/", $response, 2);
// get the status
if(preg_match("/^HTTP\/[0-9\.]+\s+(\d+)\s+/", $header, $matches)){
$status = $matches[1];
// if 200 OK
if($status == 200){
// create the parser
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
// parse!
xml_parse($xml_parser, trim($xml), true) or $g_rss_array[errors][] = xml_error_string(xml_get_error_code($xml_parser)) . " at line " . xml_get_current_line_number($xml_parser);
// free parser
xml_parser_free($xml_parser);
}
else {
$g_rss_search_array[errors][] = "Can't get feed: HTTP status code $status";
}
}
// Can't get status from header
else {
$g_rss_search_array[errors][] = "Can't get status from header";
}
}
else {
echo "<B><font color=#FF5F00>현재 연결 할 수 없습니다.<br />RSS주소또는서버문제로 잠시 후 다시 시도해 보세요.</font></B><br />";
}
}
// Feed url looks wrong
else {
$g_rss_search_array[errors][] = "Invalid url: $url";
}
// unset 변수들
unset($g_rss_search_array[channel_title]);
unset($g_rss_search_array[channel_description]);
unset($g_rss_search_array[channel_lastBuildDate]);
unset($g_rss_search_array[channel_language]);
unset($g_rss_search_array[inside_rdf]);
unset($g_rss_search_array[inside_rss]);
unset($g_rss_search_array[inside_channel]);
unset($g_rss_search_array[inside_item]);
unset($g_rss_search_array[inside_image]);
unset($g_rss_search_array[image_title]);
unset($g_rss_search_array[image_link]);
unset($g_rss_search_array[current_tag]);
unset($g_rss_search_array[current_title]);
unset($g_rss_search_array[current_link]);
unset($g_rss_search_array[current_description]);
unset($g_rss_search_array[current_pubdate]);
unset($g_rss_search_array[current_dcdate]);
unset($g_rss_search_array[current_category]);
unset($g_rss_search_array[current_comments]);
unset($g_rss_search_array[current_author]);
unset($g_rss_search_array[current_creator]);
unset($g_rss_search_array[current_source]);
return $g_rss_search_array;
}
//this function will be called everytime a tag starts
function startElement($parser, $name){
global $g_rss_search_array;
$g_rss_search_array[current_tag] = $name;
if($name == "RSS"){
$g_rss_search_array[inside_rss] = true;
}
elseif($name == "RDF:RDF"){
$g_rss_search_array[inside_rdf] = true;
}
elseif($name == "CHANNEL"){
$g_rss_search_array[inside_channel] = true;
$g_rss_search_array[channel_title] = "";
$g_rss_search_array[channel_description] = "";
$g_rss_search_array[channel_lastBuildDate] = "";
$g_rss_search_array[channel_language] = "";
}
elseif(($g_rss_search_array[inside_rss] and $g_rss_search_array[inside_channel]) or $g_rss_search_array[inside_rdf]){
if($name == "ITEM"){
$g_rss_search_array[inside_item] = true;
}
elseif($name == "IMAGE"){
$g_rss_search_array[inside_image] = true;
}
}
}
// this function will be called everytime there is a string between two tags
function characterData($parser, $data){
global $g_rss_search_array;
if($g_rss_search_array[inside_item]){
switch($g_rss_search_array[current_tag]){
case "TITLE":
$g_rss_search_array[current_title] .= $data;
break;
case "DESCRIPTION":
$g_rss_search_array[current_description] .= $data;
break;
case "LINK":
$g_rss_search_array[current_link] .= $data;
break;
case "PUBDATE":
$g_rss_search_array[current_pubdate] .= $data;
break;
case "DC:DATE":
$g_rss_search_array[current_dcdate] .= $data;
break;
case "CATEGORY":
$g_rss_search_array[current_category] .= $data;
break;
case "COMMENTS":
$g_rss_search_array[current_comments] .= $data;
break;
case "AUTHOR":
$g_rss_search_array[current_author] .= $data;
break;
case "SOURCE":
$g_rss_search_array[current_source] .= $data;
break;
case "DC:CREATOR":
$g_rss_search_array[current_creator] .= $data;
break;
}
}
elseif($g_rss_search_array[inside_image]){
switch($g_rss_search_array[current_tag]){
case "TITLE":
$g_rss_search_array[image_title] .= $data;
break;
case "LINK":
$g_rss_search_array[image_link] .= $data;
break;
case "URL":
$g_rss_search_array[image_url] .= $data;
break;
}
}
elseif($g_rss_search_array[inside_channel]){
switch($g_rss_search_array[current_tag]){
case "TITLE":
$g_rss_search_array[channel_title] .= $data;
break;
case "DESCRIPTION":
$g_rss_search_array[channel_description] .= $data;
break;
case "LASTBUILDDATE":
$g_rss_search_array[channel_lastBuildDate] .= $data;
break;
case "LANGUAGE":
$g_rss_search_array[channel_language] .= $data;
break;
}
}
}
// this function will be called everytime a tag ends
function endElement($parser, $name){
global $g_rss_search_array;
// end of item, add complete item to array
if($name == "ITEM"){
$g_rss_search_array[items][] = array(
title => trim($g_rss_search_array[current_title]),
image_title => trim($g_rss_search_array[image_title]),
image_link => trim($g_rss_search_array[image_link]),
link => trim($g_rss_search_array[current_link]),
description => trim($g_rss_search_array[current_description]),
pubdate => trim($g_rss_search_array[current_pubdate]),
dcdate => trim($g_rss_search_array[current_dcdate]),
category => trim($g_rss_search_array[current_category]),
comments => trim($g_rss_search_array[current_comments]),
author => trim($g_rss_search_array[current_author]),
source => trim($g_rss_search_array[current_source]),
dccreator => trim($g_rss_search_array[current_creator])
);
// reset these vars for next loop
$g_rss_search_array[current_title] = "";
$g_rss_search_array[image_title] = "";
$g_rss_search_array[image_link] = "";
$g_rss_search_array[current_description] = "";
$g_rss_search_array[current_link] = "";
$g_rss_search_array[current_pubdate] = "";
$g_rss_search_array[current_dcdate] = "";
$g_rss_search_array[current_creator] = "";
$g_rss_search_array[current_category] = "";
$g_rss_search_array[current_comments] = "";
$g_rss_search_array[current_author] = "";
$g_rss_search_array[current_source] = "";
$g_rss_search_array[inside_item] = false;
}
elseif($name == "RSS"){
$g_rss_search_array[inside_rss] = false;
}
elseif($name == "RDF:RDF"){
$g_rss_search_array[inside_rdf] = false;
}
elseif($name == "CHANNEL"){
$g_rss_search_array[channel][title] = trim($g_rss_search_array[channel_title]);
$g_rss_search_array[channel][description] = trim($g_rss_search_array[channel_description]);
$g_rss_search_array[channel][lastBuildDate] = trim($g_rss_search_array[channel_lastBuildDate]);
$g_rss_search_array[channel][language] = trim($g_rss_search_array[channel_language]);
$g_rss_search_array[inside_channel] = false;
}
elseif($name == "IMAGE"){
$g_rss_search_array[image][title] = trim($g_rss_search_array[image_title]);
$g_rss_search_array[image][link] = trim($g_rss_search_array[image_link]);
$g_rss_search_array[image][url] = trim($g_rss_search_array[image_url]);
$g_rss_search_array[inside_image] = false;
}
}
?>
하나는 헤드파일을 나누어 놓은 것입니다.
<?
function rss_search_array($url){
global $g_rss_search_array;
// empty our global array
$g_rss_search_array = array();
// if the URL looks ok
if(preg_match("/^http:\/\/([^\/]+)(.*)$/", $url, $matches)){
$host = $matches[1];
$uri = $matches[2];
$request = "GET $uri HTTP/1.0\r\n";
$request .= "Host: $host\r\n";
$request .= "Connection: close\r\n\r\n";
// open the connection
// 소켓 연결, 최대연결시간 10초로설정
if($http = @fsockopen($host, 80, $errno, $errstr, 10)){
// make the request
fwrite($http, $request);
// read in for max 10 seconds
$timeout = time() + 10;
while(time() < $timeout && !feof($http)) {
$response .= fgets($http, 4096);
}
// split on two newlines
list($header, $xml) = preg_split("/\r?\n\r?\n/", $response, 2);
// get the status
if(preg_match("/^HTTP\/[0-9\.]+\s+(\d+)\s+/", $header, $matches)){
$status = $matches[1];
// if 200 OK
if($status == 200){
// create the parser
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
// parse!
xml_parse($xml_parser, trim($xml), true) or $g_rss_array[errors][] = xml_error_string(xml_get_error_code($xml_parser)) . " at line " . xml_get_current_line_number($xml_parser);
// free parser
xml_parser_free($xml_parser);
}
else {
$g_rss_search_array[errors][] = "Can't get feed: HTTP status code $status";
}
}
// Can't get status from header
else {
$g_rss_search_array[errors][] = "Can't get status from header";
}
}
else {
echo "<B><font color=#FF5F00>현재 연결 할 수 없습니다.<br />RSS주소또는서버문제로 잠시 후 다시 시도해 보세요.</font></B><br />";
}
}
// Feed url looks wrong
else {
$g_rss_search_array[errors][] = "Invalid url: $url";
}
// unset 변수들
unset($g_rss_search_array[channel_title]);
unset($g_rss_search_array[channel_description]);
unset($g_rss_search_array[channel_lastBuildDate]);
unset($g_rss_search_array[channel_language]);
unset($g_rss_search_array[inside_rdf]);
unset($g_rss_search_array[inside_rss]);
unset($g_rss_search_array[inside_channel]);
unset($g_rss_search_array[inside_item]);
unset($g_rss_search_array[inside_image]);
unset($g_rss_search_array[image_title]);
unset($g_rss_search_array[image_link]);
unset($g_rss_search_array[current_tag]);
unset($g_rss_search_array[current_title]);
unset($g_rss_search_array[current_link]);
unset($g_rss_search_array[current_description]);
unset($g_rss_search_array[current_pubdate]);
unset($g_rss_search_array[current_dcdate]);
unset($g_rss_search_array[current_category]);
unset($g_rss_search_array[current_comments]);
unset($g_rss_search_array[current_author]);
unset($g_rss_search_array[current_creator]);
unset($g_rss_search_array[current_source]);
return $g_rss_search_array;
}
//this function will be called everytime a tag starts
function startElement($parser, $name){
global $g_rss_search_array;
$g_rss_search_array[current_tag] = $name;
if($name == "RSS"){
$g_rss_search_array[inside_rss] = true;
}
elseif($name == "RDF:RDF"){
$g_rss_search_array[inside_rdf] = true;
}
elseif($name == "CHANNEL"){
$g_rss_search_array[inside_channel] = true;
$g_rss_search_array[channel_title] = "";
$g_rss_search_array[channel_description] = "";
$g_rss_search_array[channel_lastBuildDate] = "";
$g_rss_search_array[channel_language] = "";
}
elseif(($g_rss_search_array[inside_rss] and $g_rss_search_array[inside_channel]) or $g_rss_search_array[inside_rdf]){
if($name == "ITEM"){
$g_rss_search_array[inside_item] = true;
}
elseif($name == "IMAGE"){
$g_rss_search_array[inside_image] = true;
}
}
}
// this function will be called everytime there is a string between two tags
function characterData($parser, $data){
global $g_rss_search_array;
if($g_rss_search_array[inside_item]){
switch($g_rss_search_array[current_tag]){
case "TITLE":
$g_rss_search_array[current_title] .= $data;
break;
case "DESCRIPTION":
$g_rss_search_array[current_description] .= $data;
break;
case "LINK":
$g_rss_search_array[current_link] .= $data;
break;
case "PUBDATE":
$g_rss_search_array[current_pubdate] .= $data;
break;
case "DC:DATE":
$g_rss_search_array[current_dcdate] .= $data;
break;
case "CATEGORY":
$g_rss_search_array[current_category] .= $data;
break;
case "COMMENTS":
$g_rss_search_array[current_comments] .= $data;
break;
case "AUTHOR":
$g_rss_search_array[current_author] .= $data;
break;
case "SOURCE":
$g_rss_search_array[current_source] .= $data;
break;
case "DC:CREATOR":
$g_rss_search_array[current_creator] .= $data;
break;
}
}
elseif($g_rss_search_array[inside_image]){
switch($g_rss_search_array[current_tag]){
case "TITLE":
$g_rss_search_array[image_title] .= $data;
break;
case "LINK":
$g_rss_search_array[image_link] .= $data;
break;
case "URL":
$g_rss_search_array[image_url] .= $data;
break;
}
}
elseif($g_rss_search_array[inside_channel]){
switch($g_rss_search_array[current_tag]){
case "TITLE":
$g_rss_search_array[channel_title] .= $data;
break;
case "DESCRIPTION":
$g_rss_search_array[channel_description] .= $data;
break;
case "LASTBUILDDATE":
$g_rss_search_array[channel_lastBuildDate] .= $data;
break;
case "LANGUAGE":
$g_rss_search_array[channel_language] .= $data;
break;
}
}
}
// this function will be called everytime a tag ends
function endElement($parser, $name){
global $g_rss_search_array;
// end of item, add complete item to array
if($name == "ITEM"){
$g_rss_search_array[items][] = array(
title => trim($g_rss_search_array[current_title]),
image_title => trim($g_rss_search_array[image_title]),
image_link => trim($g_rss_search_array[image_link]),
link => trim($g_rss_search_array[current_link]),
description => trim($g_rss_search_array[current_description]),
pubdate => trim($g_rss_search_array[current_pubdate]),
dcdate => trim($g_rss_search_array[current_dcdate]),
category => trim($g_rss_search_array[current_category]),
comments => trim($g_rss_search_array[current_comments]),
author => trim($g_rss_search_array[current_author]),
source => trim($g_rss_search_array[current_source]),
dccreator => trim($g_rss_search_array[current_creator])
);
// reset these vars for next loop
$g_rss_search_array[current_title] = "";
$g_rss_search_array[image_title] = "";
$g_rss_search_array[image_link] = "";
$g_rss_search_array[current_description] = "";
$g_rss_search_array[current_link] = "";
$g_rss_search_array[current_pubdate] = "";
$g_rss_search_array[current_dcdate] = "";
$g_rss_search_array[current_creator] = "";
$g_rss_search_array[current_category] = "";
$g_rss_search_array[current_comments] = "";
$g_rss_search_array[current_author] = "";
$g_rss_search_array[current_source] = "";
$g_rss_search_array[inside_item] = false;
}
elseif($name == "RSS"){
$g_rss_search_array[inside_rss] = false;
}
elseif($name == "RDF:RDF"){
$g_rss_search_array[inside_rdf] = false;
}
elseif($name == "CHANNEL"){
$g_rss_search_array[channel][title] = trim($g_rss_search_array[channel_title]);
$g_rss_search_array[channel][description] = trim($g_rss_search_array[channel_description]);
$g_rss_search_array[channel][lastBuildDate] = trim($g_rss_search_array[channel_lastBuildDate]);
$g_rss_search_array[channel][language] = trim($g_rss_search_array[channel_language]);
$g_rss_search_array[inside_channel] = false;
}
elseif($name == "IMAGE"){
$g_rss_search_array[image][title] = trim($g_rss_search_array[image_title]);
$g_rss_search_array[image][link] = trim($g_rss_search_array[image_link]);
$g_rss_search_array[image][url] = trim($g_rss_search_array[image_url]);
$g_rss_search_array[inside_image] = false;
}
}
?>
ㅡ,,ㅡ;; 실패했습니당...