<? -- File Total -- ?>

From: Date: Mon, 19 Feb 2001 15:25:40 +0000
Subject: <? -- File Total -- ?>
Groups: php.general 
Request: Send a blank email to php-general+get-40578@lists.php.net to get a copy of this message
Hi, I am trying to get a total value of orders from a file. The file has various fields separated by '|'. It is the 15th field I am trying to total. At the moment I am trying to search each character but it times out as the file is quite large - is there a more efficient way of doing this. Thanks - Here is the script: <?php function total($filename) { $totalfile=16; $total=0; $vartemp=""; $counterbeforeend=0; $counter=0; if(!$file=fopen($filename,"r")) { echo"Could not open the file named '$filename'"; } else { while((!feof($file))&&($total<1000)) { $char=fgetc($file); if(strcmp($char,"|")==0) $counter++; if($counter==($totalfile+1)) { $vartemp=$vartemp.$char; if((strcmp($char,".")==0)||($passed==1)) { $counterbeforeend++; $passed=1; } if($counterbeforeend==3) { $total=$total+$vartemp; $passed=0; $counter=0; $counterbeforeend=0; $vartemp=""; echo"$total<BR>\n"; } } else if($counter==$totalfile) { $counter++; } } } return($total); } ?> <HTML> <BODY> <? $total1=total("G&V_orderslist.txt"); echo"$total1"; ?> </BODY> </HTML>

« previous php.general (#40578) next »