Tuesday, June 7, 2011

Grab content with PHP script and cURL

php curl continues, after enabling curl on php setting, now let try to grab content from other website. For doing so, just follow this simple step. Fisrt, you must create a file named infokurs.php at root folder of your site and Copas following code


<?php
function bacaHTML($url){
     // inisialisasi CURL
     $data = curl_init();
     // setting CURL
     curl_setopt($data, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($data, CURLOPT_URL, $url);
     // menjalankan CURL untuk membaca isi file
     $hasil = curl_exec($data);
     curl_close($data);
     return $hasil;
}


$kodeHTML =  bacaHTML('http://www.klikbca.com');
$pecah = explode('<table width="139" border="0" cellspacing="0" cellpadding="0">', $kodeHTML);


$pecahLagi = explode('</table>', $pecah[2]);
?>
<style type="text/css">
.kurs table tr td{
font-size:90%;
}
</style>
<?php
echo '<div class="moduletable"><h3>Kurs Mata uang</h3><div class=kurs>';
echo "<table>";
echo "<tr><td align=center>KURS</td><td align=center>JUAL</td><td align=center>BELI</td></tr>";
echo $pecahLagi[0];
echo "</table></div></div>";


?>


and wallaaa... you'll see the result just like this, below


0 komentar:

Post a Comment