Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <title>Grab Kurs BKF - harviacode.com</title>
- <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"/>
- </head>
- <body>
- <div style="width: 600px; margin: 15px">
- <form action="index.php" method="post" class="form-inline">
- <input type="text" name="tgl_kurs" class="form-control" placeholder="dd-mm-yyyy" value="<?php echo isset($_POST['tgl_kurs']) ? $_POST['tgl_kurs'] : date('d-m-Y'); ?>" />
- <input type="submit" name="cari" value="Tampilkan" class="btn btn-primary" />
- </form>
- <?php
- // membuat fungsi grap url
- function grabCURL($url) {
- // aktifkan dulu ;extension=php_curl.dll di php.ini
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HEADER, 0);
- $grab = curl_exec($ch);
- curl_close($ch);
- return $grab;
- }
- if (isset($_POST['cari'])) {
- // format bkf 20150311
- $strDate_mentah = explode('-', $_POST['tgl_kurs']);
- $strDate = $strDate_mentah[2] . $strDate_mentah[1] . $strDate_mentah[0];
- $hasil = grabCURL('http://www.fiskal.kemenkeu.go.id/2010/edef-kurs-pajak-db.asp?strDate=' . $strDate);
- } else {
- $hasil = grabCURL('http://www.fiskal.kemenkeu.go.id/2010/edef-kurs-pajak-db.asp');
- }
- // mengekstrak hasil grap menjadi string sesuai keinginan kita
- // agak panjang disini, tapi pada intinya memecah dan str replace aja
- $p = explode('<p>', $hasil);
- $jumlah_p = count($p);
- // untuk menghandle hasil yang tidak ada, kita hitung jumlah element p nya
- if ($jumlah_p > 3) {
- $kep = str_replace("</p>", " ", $p[2]);
- $tgl_kep = str_replace("</p>", " ", $p[3]);
- $berlaku = explode('</p>', $p[4]);
- $berlaku = $berlaku[0];
- $pecah1 = explode('<div class="KursTable" >', $hasil);
- $pecah2 = explode("</div>", $pecah1[1]);
- $string = $pecah2[0];
- $kurs_down = 'http://www.fiskal.kemenkeu.go.id/2010/aimages/down.gif';
- $kurs_up = 'http://www.fiskal.kemenkeu.go.id/2010/aimages/up.gif';
- $string = str_replace("<img src='aimages/down.gif'>", "<img src='" . $kurs_down . "'>", $string);
- $string = str_replace("<img src='aimages/up.gif'>", "<img src='" . $kurs_up . "'>", $string);
- $string = str_replace("<table >", "<table class='table table-bordered table-condensed table-striped'>", $string);
- $string = str_replace("class='ctr'", "style='text-align:center'", $string);
- $string = str_replace("class='right'", "style='text-align:right'", $string);
- // menampilkan hasil olahan string
- echo '<br>';
- echo $kep;
- echo '<br>';
- echo $tgl_kep;
- echo '<br>';
- echo $berlaku;
- echo '<br>';
- echo '<br>';
- echo $string;
- echo '* Note : untuk JPY adalah nilai Rupiah per 100 Yen';
- } else {
- echo '<br>';
- echo 'Data tidak tersedia';
- }
- ?>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement