write array values to file
Posted: Thu Jul 22, 2010 7:17 pm
Hello,
Im trying to do a simple task of reading a csv file which i can do fine, and i read it to an array and i want to assign each value for to a variable and write it out to a text file in the order i need.
This is what i have so far.
Notice I print out $lines just fine! But i cannot write $lines to a file? The file gets created however it is empty. Whats wrong?
Thanks for the help!
Also one other thing, I cannot save $lines_of_text[1] to a file either. Nothing gets written in the txt file
Im trying to do a simple task of reading a csv file which i can do fine, and i read it to an array and i want to assign each value for to a variable and write it out to a text file in the order i need.
This is what i have so far.
Code: Select all
$file_handle = fopen("test.csv", "r");
while (!feof($file_handle) ) {
$line_of_text = fgetcsv($file_handle, 10240);
$lines = implode("<BR>",$line_of_text);
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $lines);
fclose($fh);
print $lines;
}
Thanks for the help!
Also one other thing, I cannot save $lines_of_text[1] to a file either. Nothing gets written in the txt file