<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>INT2K Blog - Think and write the code &#187; ecommerce</title>
	<atom:link href="http://www.int2k.web.id/tag/ecommerce/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.int2k.web.id</link>
	<description>Think and write the code</description>
	<lastBuildDate>Tue, 27 Jul 2010 04:56:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Parser tarif kiriman TIKI Online</title>
		<link>http://www.int2k.web.id/2009/11/parser-tarif-kiriman-tiki-online/</link>
		<comments>http://www.int2k.web.id/2009/11/parser-tarif-kiriman-tiki-online/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 15:45:00 +0000</pubDate>
		<dc:creator>int2k</dc:creator>
				<category><![CDATA[Web Coding]]></category>
		<category><![CDATA[ecommerce]]></category>
		<category><![CDATA[parser tarif tiki]]></category>
		<category><![CDATA[tiki]]></category>

		<guid isPermaLink="false">http://www.int2k.web.id/?p=271</guid>
		<description><![CDATA[TIKI / titipan kilat untuk saat ini memang belum mempunyai sebuah layanan web service untuk memudahkan para pemilik toko online dalam melakukan perhitungan tarif. Pada halaman web dari tiki online sendiri sebenarnya telah di sediakan sebuah tool untuk menghitung tarif yang dibebankan untuk sebuah pengiriman. Pada bahasan kali ini akan coba di buat sebuah parser [...]]]></description>
			<content:encoded><![CDATA[<p>TIKI / titipan kilat untuk saat ini memang belum mempunyai sebuah layanan web service untuk memudahkan para pemilik toko online dalam melakukan perhitungan tarif. Pada halaman web dari tiki online sendiri sebenarnya telah di sediakan sebuah tool untuk menghitung tarif yang dibebankan untuk sebuah pengiriman.<br />
Pada bahasan kali ini akan coba di buat sebuah parser untuk halaman penghitungan tarif tersebut. Untuk ini kita membutuhkan sebuah library tambahan yaitu &#8220;<a href="http://sourceforge.net/projects/simplehtmldom/">PHP Simple HTML DOM Parser</a>&#8221; . Library ini akan memudahkan script kita dalam memproses sebuah struktur HTML, sehingga bisa dilakukan pengambilan data-data yang di perlukan saja. Di butuhkan juga dukungan untuk cURL pada server yang kita gunakan.<br />
<span id="more-271"></span><br />
Dari halaman <a href="http://www.tiki-online.com/tardom.asp">perhitungan tarif Tiki Online</a> kita akan dapati sebuah form yang terdiri dari 3 buah input teks, yaitu Origin, Destination dan Weight. Form tersebut di arahkan ke halaman yang sama, dalam hal melakukan proses perhitungannya.<br />
<div id="attachment_280" class="wp-caption aligncenter" style="width: 430px"><img src="http://www.int2k.web.id/blog/wp-content/uploads/2009/11/hitung-tarif-tiki.gif" alt="Contoh penghitungan tarif" title="Contoh penghitungan tarif" width="420" height="159" class="size-full wp-image-280" /><p class="wp-caption-text">Contoh penghitungan tarif</p></div><br />
Berikut adalah contoh kode yang di gunakan untuk perhitungan :</p>
<pre class="brush: php">
/****************************************************************
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 &quot;simple_html_dom.php&quot;;

$url = &quot;http://www.tiki-online.com/tardom.asp&quot;;
$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&#039;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, &quot;TxtOrg=Jakarta&amp;TxtDest=Bandung&amp;TxtWg=1&quot;);//Post the fields

$text = curl_exec($ch);
curl_close($ch);
$html = str_get_html($text);
$dataall = array();

foreach( $html-&gt;find(&#039;tr[bgcolor!=#A6A5A5]&#039;) as $hasil)
{
  $data[&#039;service&#039;] =
  preg_replace(&quot;(^\s|\s$)&quot;, &quot;&quot;,
    str_replace(&quot;&amp;nbsp;&quot;, &quot;&quot;,
      str_replace(&quot;-&quot;, &quot;&quot;,
        str_replace(&quot;\r\n&quot;,&quot;&quot;,
          $hasil-&gt;find(&quot;td[width=&#039;350&#039;]&quot;,0)-&gt;plaintext.&quot; &quot;))));
  preg_match(&quot;(\(.*\))&quot;,$data[&#039;service&#039;],$kode);
  $data[&#039;kode&#039;]=preg_replace(&quot;(\(|\))&quot;,&quot;&quot;,$kode[0]);
  $data[&#039;biaya&#039;] = (float) preg_replace(&quot;([\.,])&quot;,&quot;&quot;,
    str_replace(&quot;&amp;nbsp;&quot;,&quot;&quot;,
	  str_replace(&quot;-&quot;,&quot;&quot;,str_replace(&quot;\r\n&quot;,&quot;&quot;,
        $hasil-&gt;find(&quot;td[width=&#039;250&#039;]&quot;,0)-&gt;plaintext))));
  $dataall[]=$data;
}
var_dump($dataall);
$html-&gt;clear();
$hasil-&gt;clear();
unset($html);
unset($hasil);
</pre>
<p>Hasil dari kode di atas kira-kira adalah sebagai berikut :<br />
<div id="attachment_278" class="wp-caption aligncenter" style="width: 310px"><img src="http://www.int2k.web.id/blog/wp-content/uploads/2009/11/hasil-parsing-tiki.gif" alt="Contoh hasil parsing tarif TIKI" title="Contoh hasil parsing tarif TIKI" width="300" height="431" class="size-full wp-image-278" /><p class="wp-caption-text">Contoh hasil parsing tarif TIKI</p></div></p>
<p>Bagian utama dari parser ini berada pada bagian foreach yang akan mengambil hasil dari perintah $html->find(&#8216;tr[bgcolor!=#A6A5A5]&#8216;). Perintah ini maksud nya mencari element HTML TR yang memiliki elemen bgcolor tidak sama dengan #A6A5A5. Elemen ini di pilih setelah melihat kedalam source dari halaman perhitungan tarif setelah selesai memproses form, yaitu elemen yang menampung tabel hasil perhitungan.</p>
<p>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. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.int2k.web.id/2009/11/parser-tarif-kiriman-tiki-online/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
