สคริปต์ PHP สำหรับอ่าน XML แบบง่าย ๆ

สำหรับผู้ที่สนใจจะดึงข้อมูลจากพวก RSS feed. จึงอยากจะขอแนะนำสคริปต์ XML parser แบบง่าย ๆ ลองดูสคริปต์ข้างล่างน่ะครับ

* สำหรับ (PHP 5) เท่านั้นครับ

<?
$p =“thaihits.info”;
$r =($_GET[‘place’]!=)? $_GET[‘place’] : “nst”;
$cur =($_GET[‘currency’]!=)? $_GET[‘currency’] : “USD”;
$sort =($_GET[’sort’]!=)? $_GET[’sort’] : “L”;
$src = “http://www.R24DB.com/R24xmlhotel.php?p=$p&amp;r=$r&amp;cur=$cur&amp;sort=$sort”;
$xml = simplexml_load_file($src);

print “<table>”;
foreach($xml->children() as $child)
{
echo “<tr>”;
print “<td><img src=”.$child->HTHUMB.“></td>”;
print “<td>
<strong><a href=’”
.$child->HLINK.“‘ title=’”.$child->HNAME.“‘ target=’_blank’>”.$child->HNAME.“</a></strong>”.(($child->HPROMO==‘YES’)? ” [Recommend] “:“”).“<br />
.$child->HLOCATION.“<br />
Breakfast : “
.$child->HINCLABF.” - 10% Service : “.$child->HINCLSVC.” - 7% gov.VAT : “.$child->HINCLVAT.
</td>”
;
print “<td><h4><font color=red>”.$child->HRATE.“</font></h4></td>”;
echo “</tr>”;
}
print “</table>”;

?>

About the Author