hello,
is there anyone out there who can help me out with this thing? goin nuts over here. i got a long text file, comma delimeted with each line representing a product i need to import.. i've done a bunch of other things with this file so far using the method below, but now i want to change the price of each item by exploding a line, changing the price element, then imploding back to a string for 'fputs' in my destination file. It works on the first line of text fine, and loops through all the other lines and 'fputs' them as well with no errors, but doesn't operate on the price like with the first line. all i can see is that my $line array keeps adding to the end instead of resetting.. i tried using reset and unset, but wasn't working either, was probably doing it wrong.. am i missing something obvious?
$fs = fopen( 'source.txt', 'r' );
$formatted= fopen('destination.txt', 'w');
while (!feof( $fs) )
{
$line = fgets( $fs);
$line = explode(",", $line);
$line[3] = $line[3] * 1.80; # change the price of item
print "$tmp[3]"; # test result
$line = implode(",", $line); #change back to string
fputs($formatted, $line);
}
#closes files
fclose( $fs );
fclose( $formatted );