WEB/PHP
[PHP] 외부 사이트의 xml긁어오기
Ezcode
2013. 1. 8. 20:45
rss로 제공하는 xml이 있을시
본 사이트로 해당 xml을 파싱하여 가져와야 할 경우
$xml = "xxx.com/aaa.php";
$doc = new DOMDocument();
$doc->load($doc);
if(!$doc) { // 불러올수 없다면
echo "not";
} else {
$items = $doc->getElementsByTagName('item'); // 반복되는 item태그중
$records = array();
foreach($items as $item) {
$record = array();
if($item->childNodes->length) {
foreach($item->childNodes as $i) {
if($i->nodeName != 'title' && $i->nodeName != 'link') continue; // title태그와 link태그만 긁어오고 싶다.
$record[$i->nodeName] = iconv('utf-8','euc-kr',$i->nodeValue); // euc-kr로 할거니까
}
}
$records[] = $record;
}
}
}