Hi,

When I try to run this, I get an error saying "invalid file permissions"
and will not run.  However, I then run it using php -q bank.php and this
works fine.

Unfortunately, there is a parse error on line 68 (apparantly) which I
cannot figure out.

Can anyone help me here?

Thanks in advance,

David Apthorpe.
#!/usr/bin/php -q
<?php

function arrayvaluefinder ($searchvalue)
{
        global $argv;
        if (!(array_search ($searchvalue, $argv))===FALSE) {
                return $argv[array_search ($searchvalue, $argv) +1];
        }
        return "";
}

function returnhelp () { exit(5);
}

$error=fopen("php://stderr","w-");

//help function, if not enough arguments, help is called, or the first argument
//is too short

if ($argc==1 || ($argv[1]=='-h')) {
returnhelp();
exit(0);
//if help isnt wanted!

} else {
    $info[0] = arrayvaluefinder("-d");
    $info[1] = arrayvaluefinder("-a");
    $info[2] = arrayvaluefinder("-v");
    $info[3] = arrayvaluefinder("-p");
    $info[4] = arrayvaluefinder("-n");
    $info[5] = arrayvaluefinder("-f");


// Check that if referenced, it is a value, and isnt just put in


        if(strlen($argv[1]) !=2) {
                $david = fwrite($error, "You cannot perform more than one operation at 
once\n");
        exit(2);
    }
    for($i=2;$i<$argc;$i+=2) {
    if(!(ereg ("-[adfnpv]", $argv[$i]))) {
                exit(3);
    }
    }
    if(!(ereg ("-[AFDTh]", $argv[1]))) {
                exit(4);
    }
        if(($argc % 2)==1) {
        exit(6);
    }
        if(ereg ("[A-Za-z:]", $info[2])) {
        exit(7);
    }

    //disallowed characters
    $dead=":";
    if(ereg ($dead, $info[0])||ereg ($dead, $info[1])||ereg ($dead, $info[3])||ereg 
($dead, $info[4])||ereg ($dead, $info[5])) {
                        $david = fwrite($error, "You cannot have text in the value 
field\n");
                exit(2);
    }


if($info[5]=="") {
  $info[5]="bank.dat";
}

if(file_exists($info[5]){
        if(!(is_readable($info[5])||!(is_writable($info[5]))) {
        fwrite($error, "You do not have the appropriate access\n");
        exit(2);
    }
    }

$fileopen = fopen($info[5],"a+") or exit(1);
rewind($fileopen);
if ($argv[1]=="-A"){
        if($info[0]=="") $info[0]=date("Y.m.d");
        if($info[1]=="") $info[1]="current";
        if($info[2]=="") $info[2]="0.00";
        fwrite($fileopen, 
$info[0].":".$info[1].":".$info[2].":".$info[3].":".$info[4]."\n");
}

//Delete Function

if ($argv[1]=="-D"){
        $toappend="";
        while($david = fgetcsv ($fileopen, 1024, ":")) {
                if ($david!=NULL) {
                        $checktotal = 0;
                        for($i=0;$i<5;$i++) {
                                if(($info[$i]=="")||($info[$i]==$david[$i])){
                                $checktotal++;
                                }
                        }
                        if($checktotal!=5) {
                                $toappend = $toappend . implode(":", $david) . "\n";

                        }
                }
        }
                        fclose($fileopen);
                    $fileopen = fopen($info[5],"w+") ;
                fwrite($fileopen, $toappend);



}

//implements a find function

if ($argv[1]=="-F"){
        while($david = fgetcsv ($fileopen, 1024, ":")) {
                if ($david!=NULL) {
                        $checktotal = 0;
                        for($i=0;$i<5;$i++) {
                                if(($info[$i]=="")||($info[$i]==$david[$i])) 
$checktotal++;
                        }
                        if($checktotal==5) {
                                for($i=0;$i<5;$i++) {
                                        echo("$david[$i] ");
                                }
                        }
                }
                echo("\n");
        }
}

//implements a totalling function

if ($argv[1]=="-T"){
                $total=0;
                        while($david = fgetcsv ($fileopen, 1024, ":")) {
                                if ($david!=NULL) {
                                        $checktotal = 0;
                                        for($i=0;$i<5;$i++) {
                                                
if(($info[$i]=="")||($info[$i]==$david[$i])) $checktotal++;
                                        }
                                        if($checktotal==5) $total = $total+$david[2];
                                }
                        }
                echo("Total: $total");
        }
}
fclose($fileopen);
fclose($error);
exit(0);
?>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to