Get Latest Exchange Price with PHP

ကျွန်တော်ရေးထားတဲ့ bot ကိုတော့ ပိတ်လိုက်ပြီ။ အဲဒီ bot အတွက် ရေးထားတဲ့ service လေးတစ်ခုရှိတယ်။ သို့ပေမယ့်လည်း server loading တက်မှာဆိုးလို့ မထည့်တော့ပဲ ပိတ်လိုက်တာ။ ကျွန်တော် http://www.naungmon.co.cc/ ကနေ နောက်ဆုံး ပေါက်ဈေးကို သိရအောင် PHP နဲ့ ရေးလို့ရပါတယ်။ ဥပမာ။။ website ကို သွားစရာ မလိုပဲ အောက်ကလို မြင်ရမှာပါ။

SGD To Kyats

24 Jun
1SGD– 715 Ks


အဲဒီလို မြင်ရဖို့အတွက် ဒီလိုလေးရေးရပါတယ်။

[lang name=php]
<?php
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, “http://www.naungmon.co.cc/”);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// grab URL and pass it to the browser
$store = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
$doc = new DOMDocument();
//avoid error
@$doc->loadHTML($store);
$xpathvar = new Domxpath($doc);
$queryResult = $xpathvar->query(‘//div[@id=”Layer1″]/table/tbody/tr/td’);
echo “<h2>SGD To Kyats</h2>”;
echo $queryResult->item(0)->textContent;
echo “<br/>”;
echo “1SGD”;
echo “–“;
echo $queryResult->item(2)->textContent;

?>
[/lang]

CURL နဲ့ website ဆီကိုသွားပြီး xpathquery နဲ့ ပြန်ပြီး ဆွဲထုတ်ကာ result တွေကို ပြန်ဖော်ပြပေးတာပါ။ XAMPP လေးသွင်းပြီး ကိုယ့် localhost လေးမှာ run ပြီး ကြည့်လို့ရပါတယ်။

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Saturngod

Subscribe now to keep reading and get access to the full archive.

Continue reading