[ php ] xml 파싱 ( snoopy 스누피를 이용한 것과 파일을 이용하는 것)
페이지 정보
작성자 웹지기 댓글 0건 조회 6,813회 작성일 18-09-27 14:15본문
1. 스누피 이용시
[code]
include 'Snoopy.class.php';
$snoopy = new Snoopy;
$getUrl = "<a href="http://nwww.koreaherald.com/common_prog/rssdisp.php?ct=020600000000.xml";//">http://nwww.koreaherald.com/common_prog/rssdisp.php?ct=020600000000.xml";//</a> 가져올 사이트
$snoopy->fetch($getUrl);
$xml = @simplexml_load_string($snoopy->results);
$listct = '30'; //첫 파싱후 2번째부터는 수량조절용으로 사용(최적화를 위해)
for($i=0; $i<$listct; $i++){
$wr_subjects = $xml->channel->item[$i]->title;
$category[$i] = $xml->channel->item[$i]->category;
$link[$i] = $xml->channel->item[$i]->link;
$dcDate[$i] = $xml->channel->item[$i]->dcdate;
$author[$i] = $xml->channel->item[$i]->author;
$wr_contents = $xml->channel->item[$i]->description;
$pub_datetime = date('Y-m-d H:i:s', strtotime(str_replace(',', '', $item->pubDate)));
//파싱값의 아이디를 넣자
$wr_1 = $xml->channel->item[$i]->guid;
$wr_subject = addslashes(trim($wr_subjects));
$wr_content = addslashes(trim($wr_contents));
$bo_table = "test";
$write_table = "g4_write_{$bo_table}";
$wr_num = get_next_num($write_table);
$wr_reply = "";
$parse_writer = "익명";
//$sql = " select * from $write_table where wr_subject = '$wr_subject' ";
$sql = " select * from $write_table where wr_1 = '$wr_1' ";
$result = sql_fetch($sql);
if ($result['wr_1'] == "$wr_1") {
/*$sql = " insert into $write_table
set wr_num = '$wr_num',
wr_reply = '$wr_reply',
wr_comment = 0,
wr_option = 'html1',
ca_name = '$ca_name',
wr_subject = '$wr_subject',
wr_content = '$wr_content',
wr_link1 = '',
wr_link2 = '',
wr_link1_hit = 0,
wr_link2_hit = 0,
wr_trackback = '',
wr_hit = 0,
wr_good = 0,
wr_nogood = 0,
mb_id = 'admin',
wr_password = '',
wr_name = '$parse_writer',
wr_email = '',
wr_homepage = '',
wr_datetime = '$parse_date',
wr_last = '$parse_date',
wr_ip = '$_SERVER[REMOTE_ADDR]',
wr_1 = '$wr_1',
wr_2 = '',
wr_3 = '$parse_num',
wr_4 = '1',
wr_5 = '$wr_5',
wr_6 = '$wr_6',
wr_7 = '$wr_7',
wr_8 = '$wr_8',
wr_9 = '',
wr_10 = '' ";
sql_query($sql);
$wr_id = mysql_insert_id();
sql_query(" update $write_table set wr_parent = '$wr_id' where wr_id = '$wr_id' ");
sql_query("update $g4[board_table] set bo_count_write = bo_count_write + 1 where bo_table = '$bo_table'");
*/
echo("1111");
}else{
echo("2222");
}
}
[/code]
일반 파일을 불러들일때
[code]
$g4_path = ".";
include_once($g4_path."/lib/common.php");
$xml_file="test.xml";
if (file_exists($g4[path]."/".$xml_file)){
$xml = simplexml_load_file($g4[path]."/".$xml_file);
$row = $xml -> xpath("ResultSet");
$row2 = $xml->ResultSet;
$listCnt = count($row);
print_r2($row2);
print_r2($row);
}
?>
[/code]
댓글목록
등록된 댓글이 없습니다.