ตัวอย่างนี้แค่ดึงหัวข้อข่าวมาโชว์เท่านั้นนะครับ เอาไปปรับปรุงกันดูนะ
<?php
$xml = "http://www.thairath.co.th/rss/news.xml";
$filename = $xml;
$count = 0;
$dom = new DOMDocument();
if ($dom->load($filename)) {
$title = $dom->getElementsByTagName("title")->item(0)->nodeValue;
//echo $title."<hr>\n";
$data = $dom->getElementsByTagName("item");
foreach($data as $theData) {
$news[$count]['title'] = trim($theData->getElementsByTagName("title")->item(0)->nodeValue);
$news[$count]['description'] = trim($theData->getElementsByTagName("description")->item(0)->nodeValue);
$news[$count]['link'] = trim($theData->getElementsByTagName("link")->item(0)->nodeValue);
$news[$count]['image'] = trim($theData->getElementsByTagName("enclosure")->item(0)->getAttribute('url'));
echo '<a href="'.$news[$count]['link'].'">'.$news[$count]['title']."</a><br /><br />";
++$count;
}
} else {
echo("This document is not valid!");
}
?>
ลองดูตัวอย่างที่ปรับปรุงแล้วได้ที่ marketviva.com เลยครับ