<?php
$url = "http://www.jne.co.id/index.php?mib=tariff&lang=IN";
$ch = curl_init();//Initialise CURL
curl_setopt($ch, CURLOPT_URL, $url);//Set the url
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);//We want the data to return
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 100);//Of course, we don't want your script to run forever, so set a timeout
curl_setopt($ch, CURLOPT_POST, true);//We want to request the page by post
$post_data = array("from" => "JAKARTA",
"origin_code" => "Q0dLMTAwMDBK",
"to" => "BANDUNG",
"destination_code" => "QkRPMTAwMDBK",
"weight" => "3",
"checktariff" => "" );
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
//Post the fields
$text = curl_exec($ch);
curl_close($ch);
echo $text;
Contoh penghitungan tarif
/**************************************************************** Version: 0.01 Website: http://www.int2k.web.id/ Author: int2k Licensed under The MIT License Redistributions of files must retain the above copyright notice. *****************************************************************/ include "simple_html_dom.php"; $url = "http://www.tiki-online.com/tardom.asp"; $ch = curl_init();//Initialise CURL curl_setopt($ch, CURLOPT_URL, $url);//Set the url curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);//We want the data to return curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 10);//Of course, we don't want your script to run forever, so set a timeout curl_setopt($ch, CURLOPT_POST, true);//We want to request the page by post curl_setopt($ch, CURLOPT_POSTFIELDS, "TxtOrg=Jakarta&TxtDest=Bandung&TxtWg=1");//Post the fields $text = curl_exec($ch); curl_close($ch); $html = str_get_html($text); $dataall = array(); foreach( $html->find('tr[bgcolor!=#A6A5A5]') as $hasil) { $data['service'] = preg_replace("(^\s|\s$)", "", str_replace(" ", "", str_replace("-", "", str_replace("\r\n","", $hasil->find("td[width='350']",0)->plaintext." ")))); preg_match("(\(.*\))",$data['service'],$kode); $data['kode']=preg_replace("(\(|\))","",$kode[0]); $data['biaya'] = (float) preg_replace("([\.,])","", str_replace(" ","", str_replace("-","",str_replace("\r\n","", $hasil->find("td[width='250']",0)->plaintext)))); $dataall[]=$data; } var_dump($dataall); $html->clear(); $hasil->clear(); unset($html); unset($hasil);
Hasil dari kode di atas kira-kira adalah sebagai berikut :
Contoh hasil parsing tarif TIKI
Kode di atas hanya merupakan sebuah kode dasar, namun cukup lengkap untuk kemudian digunakan dalam membantu perhitungan sesungguhnya pada sebuah toko online. Silahkan jika ada yang ingin mengembangkan lebih lanjut sehingga bisa langsung di pakai sebagai modul pada script e-commerce.
Tidak ada komentar:
Posting Komentar