classKurs is a PHP class that lets you grab Bank Indonesia's content of kurs, then put the content on a single file. The grabber can be set as cron job. There is also the function to show the grabbed file in formated html tags, ready to go.
By : hermawan
<?php
/***********************************************
* Class Name : classKurs *
* Scripted By : Hermawan Haryanto *
* Website : http://hermawan.com *
* Email : hermawan@codewalkers.com *
* License : GPL (General Public License) *
* Created Date : 09/08/2001 *
* Last Update : 11/11/2002 *
* Instruction : Read INSTALL *
***********************************************/
class kurs {
var $admin;
var $file;
var $graburl;
var $chop;
var $choptitle;
var $jual = Array ();
var $beli = Array ();
var $titles = Array ();
var $temp;
function kurs() {
global $conf;
$this->admin = $conf["admin"];
$this->file = $conf["file"];
$this->graburl = $conf["graburl"];
$this->chop = $conf["chop"];
$this->choptitle = $conf["choptitle"];
$this->textTitle = $conf["textTitle"];
$this->textKurs = $conf["textKurs"];
$this->textBuy = $conf["textBuy"];
$this->textSell = $conf["textSell"];
}
function writeToFile() {
$fp = fopen($this->file,"w+");
@fwrite($fp,$this->temp);
@fclose($fp);
}
function grab() {
$fp = fopen ($this->graburl,"r");
$fp2 = fopen ($this->graburl,"r");
if (!$fp) {
$this->sendAdminError();
exit();
}
$this->getKurs ($fp);
$this->getTitles ($fp2);
$this->formatText();
$this->writeToFile();
}
function formatText() {
for ($i=0;$i<count($this->titles);$i++) {
$this->temp .= $this->titles[$i]."|".$this->jual[$i]."|".$this->beli[$i]."|".time()."\n";
}
}
function getTitles ($fp) {
while(!feof($fp)){
$data = fgets($fp, 4096);
if(ereg($this->choptitle,$data,$arr)) $this->titles[] = trim($arr[1]);
}
}
function getKurs($fp) {
while(!feof($fp)){
$data = fgets($fp, 4096);
if(ereg($this->chop,$data,$arr)){
if ($i%2==0) $this->jual[] = str_replace(",","",trim($arr[1]));
else $this->beli[] = str_replace(",","",trim($arr[1]));
$i++;
}
}
}
function sendAdminError() {
$to = $this->admin;
$subject = "Kurs::Error";
$message = "Your Homepage\n";
$message.= "Kurs Module (".$_SERVER["SERVER_NAME"].")is generating this Error.\n";
$message.= "Please check!.\n\n";
$message.= "[MalFunction]";
$headers.= "From: Hermawan Haryanto <hermawan@dmonster.com>\r\n";
$headers.= "Reply-To: Hermawan Haryanto <hermawan@haryan.to>\r\n";
$headers.= "X-Mailer: Hermawan Haryanto";
@mail($to,$subject,$message,$headers);
}
function show() {
$fp = @file($this->file);
$rtn .= "<table width=100% border=0 cellpadding=0 cellspacing=0><tr><td><table width=100% border=0 cellpadding=2 cellspacing=1 bgcolor=#EEEEEE><tr class=header><td align=center valign=middle>$this->textTitle</td></tr><tr><td align=center valign=middle bgcolor=#FFFFFF><table width=100% border=0 cellspacing=1 cellpadding=2><tr align=center valign=top bgcolor=#CCCCCC class=subtitle><td>$this->textKurs</td><td width=100>$this->textSell</td><td width=100>$this->textBuy</td></tr>";
for ($i=0;$i<count($fp);$i++) {
list ($mtu, $jual, $beli, $lastupdate) = explode("|", $fp[$i]);
$rtn .= "<tr align=left valign=top class=body><td>$mtu</td><td>Rp.".number_format($jual,2,",",".")."</td><td>Rp.".number_format($beli,2,",",".")."</td></tr>";
}
$rtn .= "</table></td></tr><tr><td align=center valign=middle class=body>Update : ".date("j/n/Y H:i:s",$lastupdate)."</td></tr></table>";
$rtn .= "</td></tr><tr><td align=center>";
$rtn .= "<a href=\"http://www.bi.go.id/bank_indonesia2/moneter/kurs_valuta/default.asp\">Bank Indonesia</a>";
$rtn .= "</td></tr></table>";
return $rtn;
}
};
$fixpath = dirname(__FILE__);
require_once ($fixpath."/ckConfig.php");
$kurs = new kurs($conf);
?>
Click to
Download File| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Miscellaneous Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Get a free trial download of the latest version of IBM Rational Performance Tester V7.0.1, a load and performance testing solution for teams concerned about the scalability of their Web-based applications. Combining multiple ease-of-use features with granular detail, Rational Performance Tester simplifies the test-creation, load-generation and data-collection processes that help teams ensure the ability of their applications to accommodate required user loads. FREE! Go There Now!
|
|
|
|
Manage, govern, and share services across your organization by using WebSphere Service Registry and Repository. Follow the hands-on exercises to learn how to navigate the Web interface to publish, find, reuse, and update services. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on November 29 at 1:00 pm ET to participate in an interactive discusssion with Grady Booch around architecture and reuse. Get your questions answered! FREE! Go There Now!
|
|
|
|
This Fall, IBM Rational talks to you directly through a special teleconference series giving you access to the best minds in IBM Rational - product experts and market thought leaders who will answer your questions during these pre-scheduled telephone conference calls. Register today! FREE! Go There Now!
|
|
|
|
As organizations integrate software into every aspect of business, they are constantly pressured to deliver faster, better, and cheaper results. Unfortunately, a “dis-integrated” software delivery approach reduces returns while increasing costs. This IBM Rational White Paper shows how Integrated Requirements Management aligns organizations around maximizing value and keeping pace with change. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to try the IBM SOA Sandbox for connectivity. The SOA Sandbox for connectivity provides a trial environment with the tooling and components to help you explore how to effectively connect your infrastructure and integrate all of the people, processes and information in your company. Use the hosted sandbox to explore SOA techniques that streamline connecting existing IT assets together, as well as learn how to connect them to new business logic. FREE! Go There Now!
|
|
|
|
Learn field-tested SOA principles, methodology, technology and implementation from the global SOA market leader - in a new e-book by an IBM SOA expert. Written by IBM Certified SOA Solution Designer Bobby Woolf, "Exploring IBM SOA Technology & Practice" is the ultimate insider's guide to SOA - a PDF e-book packed cover to cover with IBM's specific advice on how to make your SOA implementation a success. FREE! Go There Now!
|
|
|
|
Viper 2 brings a great value to developer communities including SQL, XML, PHP, Ruby, .NET and Java. You probably already know that DB2 Express-C is free for developers to develop, deploy and distribute. Viper 2 provides a variety of means that help move your application from the development stage to deployment more rapidly. This webcast shows how to best utilize the latest tools available for developing DB2 applications. FREE! Go There Now!
|
|
|
|
Learn the basics of the IBM Customer Information Control System (CICS). With a hands-on exercise, learn how to get your first CICS application up and running on your desktop using TXSeries V6.1 for Windows. The tutorial shows you how to download and install a free trial version of TXSeries V6.1. FREE! Go There Now!
|
|
|
|
Analysts, architects, and developers who have existing COBOL or PL/I skills and want to extend those skills to deploy new workloads on the mainframe can use the IBM Enterprise Modernization Sandbox for System z to find hands-on walkthroughs of common real world scenarios. The scenarios provide examples of how to rapidly design, create, assemble, test, and deploy high-quality Web, Web services, portal, and SOA applications for IBM CICS, IBM IMS, and IBM WebSphere Application Server. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |