게시판 RSS&XML에 이미지정보 추가하는 방법 알려주세요~~

게시판 RSS&XML에 이미지정보 추가하는 방법 알려주세요~~

QA

게시판 RSS&XML에 이미지정보 추가하는 방법 알려주세요~~

본문

RSS 혹은 XML에서 살펴보면 <description></description>이 부분에 이미지 및 텍스크가 모두 들어오도록 설정되여 있습니다.

 

저는 이부분은 텍스트만 들어오도록 설정한 다음 첫번째 이미지 주소(1개)만 따로 뽑아오고 싶습니다.

<description>매일 4억 개씩 버려지는 일회용 막대....</description>

 

<image><img src="http://www.bizion.com/data/editor/1711/b22945a6031cc1e1802ef6867d2f44c6_1510790153_2494.png"  /></image>

 

위와 같이 이미지 정보를 출력하고 싶습니다.

 

어덯게 하면 가져올 수 있나요???

 

 

========

<?php

include_once "_common.php";

 

header("Content-type: text/xml;charset=utf-8");

header("Cache-Control: no-cache, must-revalidate");

header("Pragma: no-cache");

 

//출력 리스트 제한

$limit = 6;

 

// 특수문자 변환

function specialchars_replace($str, $len=0) {

if ($len) {

$str = substr($str, 0, $len);

}

$str = str_replace(array("&", "<", ">"), array("&", "<", ">"," "), $str);

$str = preg_replace("/&/", "&", $str);

$str = preg_replace("/</", "<", $str);

$str = preg_replace("/>/", ">", $str);

return $str;

}

 

// 날짜 공백 없애기

function datetime_replace($str) {

 

$str = preg_replace("/-/", "", $str);

$str = preg_replace("/:/", "", $str);

$str = preg_replace("/ /", "", $str);

 

return $str;

}

 

$buff = '';

 

$buff .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>".PHP_EOL;

$buff .= '<rss version="2.0" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" xmlns:activity="http://activitystrea.ms/spec/1.0/" >'.PHP_EOL;

$buff .= '<channel>'.PHP_EOL;

$buff .= '<title><![CDATA['.$config['cf_title'].']]></title>'.PHP_EOL;

$buff .= '<link>http://bizion.com</link>'.PHP_EOL;

$buff .= '<description><![CDATA['.$config['cf_1'].']]></description>'.PHP_EOL;

$buff .= '<language>ko</language>'.PHP_EOL;

 

$Search = " where (1) ";

$Search .= " and wr_is_comment = 0 ";

$SelectBoard = " select bo_table,bo_subject from ".$g5['board_table']." where bo_use_search = 1 ";

$QueryBoard = sql_query($SelectBoard);

while($RowBoard = sql_fetch_array($QueryBoard)){ $ResultSelect[] = "( select *, '".$RowBoard['bo_table']."' as bo_table from ".$g5['write_prefix'].$RowBoard['bo_table'].$Search." )"; }

$ResultQuery = implode(" union all ", $ResultSelect);

$ResultQuery .= " order by wr_datetime desc limit 0 , $limit ";

$Query = sql_query($ResultQuery);

while($Row = sql_fetch_array($Query)){

 

$content = strip_tags($Row['wr_content']);

$content = str_replace(" "," ",$content);

 

$board = sql_fetch("select bo_subject from g5_board where bo_table = '".$Row['bo_table']."'");




 

$buff .= "<item>".PHP_EOL;

//$buff .= "<category><![CDATA[".$board['bo_subject']."]]></category>".PHP_EOL;

$buff .= "<title><![CDATA[".$Row['bo_subject']." - ".$Row['wr_subject']."]]></title>".PHP_EOL;

$buff .= "<link>".G5_BBS_URL."/board.php?bo_table=".$Row['bo_table']."&wr_id=".$Row['wr_id']."</link>".PHP_EOL;

 

$buff .= "<description><![CDATA[".mb_strimwidth($content,0,150,'..','utf-8')."]]></description>".PHP_EOL;

$buff .= "<author>".$Row['wr_name']."</author>".PHP_EOL;

$buff .= "<pubDate>".date("D, d M Y H:i:s T", strtotime($Row['wr_datetime']))."</pubDate>".PHP_EOL;

 

$buff .= "</item>".PHP_EOL;

}

 

$buff .= "</channel>".PHP_EOL;

$buff .= "</rss>";


 

echo $buff;


 

?>

====

이 질문에 댓글 쓰기 :

답변 3

$buff .= "<item>".PHP_EOL; <---윗줄에 추가

$file= get_file($Row['bo_table'] , $Row['wr_id']);

 

원하는 위치에 추가

$buff .= "<image><img src=\"{$file[0]['path']}/{$file[0]['file']}\"></image>";

 

 

$file= get_file($Row['bo_table'] , $Row['wr_id']);


$buff .= "<item>".PHP_EOL;
//$buff .= "<category><![CDATA[".$board['bo_subject']."]]></category>".PHP_EOL;
$buff .= "<title><![CDATA[".$Row['bo_subject']." - ".$Row['wr_subject']."]]></title>".PHP_EOL;
$buff .= "<link>".G5_BBS_URL."/board.php?bo_table=".$Row['bo_table']."&amp;wr_id=".$Row['wr_id']."</link>".PHP_EOL;
$buff .= "<image><img src=\"{$file[0]['path']}/{$file[0]['file']}\"></image>";
$buff .= "<description><![CDATA[".mb_strimwidth($content,0,150,'..','utf-8')."]]></description>".PHP_EOL;
$buff .= "<author>".$Row['wr_name']."</author>".PHP_EOL;
$buff .= "<pubDate>".date("D, d M Y H:i:s T", strtotime($Row['wr_datetime']))."</pubDate>".PHP_EOL;

$buff .= "</item>".PHP_EOL;
}

균이님께서 알려주신대로 작업했으나 에러가 나오고 있습니다.

소스보기에서 보면 <image><img src="/"></image> 이렇게만 출력되네요~~

$file= get_file($Row['bo_table'] , $Row['wr_id']);

print_r($file); <----추가해서 내용이 나오는지 확인 해보고 내용이 없으면

echo $Row['bo_table'] .'///'. $Row['wr_id']; <---- 추가해서 두가지 값이 나오는지 보세요

 

우선 답변 주셔서 감사합니다.
균이 님이 알려주신대로 아래와 같이 수정했지만 이미지 주소를 가져오지 못하고 있으며 계속 에러 메시지가 나오고 있습니다.
$file= get_file($Row['bo_table'] , $Row['wr_id']);
print_r($file);
echo $Row['bo_table'] .'///'. $Row['wr_id'];

$buff .= "<image><img src=\"{$file[0]['path']}/{$file[0]['file']}\"></image>";

$imageurl1 = substr($row['wr_content'], strpos($row['wr_content'], '<img src="')+10, 100);

$imageurl2 = substr($imageurl1, 0, strpos($imageurl1, '"'));

 

<image><?php echo specialchars_replace($imageurl2) ?></image>

 

지인의 도움으로 자체 해결하였습니다.

답변을 작성하시기 전에 로그인 해주세요.
전체 67
QA 내용 검색
filter #xml ×

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT