file questions

ok, i got another question on files. I have to (yet again) change our pay system to create 1 tab delimited file. This has to involve reading multiple files (depending on the store) and then grabbing the dollar amount, adding it all up, then create a new file.

I haven’t started in on it, but from the research i’ve done, i know i’ll have to open each file, read each line into a string, then explode each line so i can work with each value. Also need a way to convert strings into numbers (though i think there’s already post in here on that subject), since you can’t add strings together (or can you?).

I’ve never done anything like this before, i’m hoping someone can point me in the right direction on how to accomplish this.

If you can, please post some sample/dummy data or describe the inputs/outputs in more detail so I can provide a more throughout answer.

Well, right now i don’t have any code, other than what i use to create the individual pay files and that’s just a simple foreach loop and a db query.

This creates the data
[php]$data .= $email."\t".$total."\tUSD\tMUSC-".($num / 100 < 0.99 ? ‘0’ : ‘’).($num / 10 < 0.99 ? ‘0’ : ‘’)
.$num."\tDear “.$key.”. Please accept your sales payment for your monthly royalties. Thank you for becoming apart of the VMG Family!\n";[/php]
and this writes it
[php]do{
$filename = ‘reports_’.date(‘d-m-y’).’_’.rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).rand(0,9).’.txt’;
} while(file_exists(‘report_files/’.$filename));

$fh = fopen(‘report_files/’.$filename, ‘w+’);
fwrite($fh, $data);
fclose($fh);[/php]
All of it is inside the foreach loop

What i end up with is
[email protected] 0.02 USD MUSC-001 Dear Best wishes. Please accept your sales payment for your monthly royalties. Thank you for becoming apart of the VMG Family!

Check this out!

[php]<?php
$a = “0.01”;
$b = “0.02”;

$c = $a+$b;
echo $c;
?>[/php]

OUTPUT?

0.03

go ahead and add your strings as long as they are all numbers.

Sponsor our Newsletter | Privacy Policy | Terms of Service