PDA

View Full Version : Help me in this PHP script


shanon
Sun 12th Aug '01, 4:21pm
Hello

Anyone can help me in this PHP script (currency converter )

Always give me this massage “too few arguments” ...




thanx for all





#!/usr/local/bin/php -q
<?php
# version 0.3.0

define("self",$argv[0]);
if($argv[1]=="-h" || $argv[1]=="--help")phelp("",1);
if($argv[1]=="--currencies" || $argv[1]=="-c"){
$f=file("http://www.oanda.com/converter/classic?user=Tihan");
while(list($k,$v)=each($f)) {
$b.=$v;
}
$bb=explode("<small><SELECT",$b);
$bbb=explode("</SELECT>",$bb[2]);
print strstr(strip_tags($bbb[0]),"\n");
exit;
}


if($argv[1]=="-n" || $argv[1]=="--numeric") {
if(!$argv[4])phelp("too few arguments");
$value=$argv[2];
$from=strtoupper($argv[3]);
$to=strtoupper($argv[4]);
if($argv[5])$date="&date=$argv[5]&date_fmt=us";
} else {
if(!$argv[3])phelp("too few arguments");
$value=$argv[1];
$from=strtoupper($argv[2]);
$to=strtoupper($argv[3]);
if($argv[4])$date="&date=$argv[4]&date_fmt=us";
}

$f=file("http://www.oanda.com/converter/classic?value=$value&exch=$from&expr=$to&user=Tihan$date");
while(list($k,$v)=each($f)) {
$b.=$v;
}
$bb=explode("<BIG>",$b);
$bbb=explode("</BIG>",$bb[1]);

if($bbb[0]=="<STRONG>To</STRONG>" || !ereg("([A-z]{1,})",$bbb[0])){
phelp("check your arguments (date wrong?)");
} else {
if($argv[1]=="-n" || $argv[1]=="--numeric") {
$bbbb=explode("=",$bbb[0]);
print ereg_replace("[A-z ,]","",$bbbb[1])."\n";
} else {
print $bbb[0]."\n";
}
}

function phelp($h="",$hh=0) {
if($h)print self.": $h\n";
print "usage: ".self." [-n] amount currency-from currency-to [mm/dd/yy]\n";
print " ".self." [-c|-h]\n";
if($hh){
print "-n, --numeric numeric output\n";
print "-c, --currencies show all available currencies with abbreviations\n";
print "-h, --help show this help\n";
}
exit;
}
?>

Mark Hensler
Sun 12th Aug '01, 6:02pm
I see one thing off the bat...
define("self",$argv[0]);
where is $argv[0] defined?

Can you give us the whole error (should include function name and line or error)?