|
Posted by Pete on 01/07/06 22:11
I am having a file with this content:
a,2
b,1
c,3
d,4
I read it from a php script, import it into arrays and recreate the file
content from the arrays and write it into the file again. The file now looks
like this:
a,2
b,1
c,3
d,4
Where do the extra line breaks come from!? The script looks like this:
<?
$filename = "test.txt";
// Read file and import into arrays
$file_lines = file($filename);
for($i=0; $i<count($file_lines); $i++) {
$split = explode(",", $file_lines[$i]);
$arr1[$i] = $split[0];
$arr2[$i] = $split[1];
}
// Create file content from arrays and write to file
for($i=0; $i<count($arr1); $i++) {
$file_txt .= $arr1[$i].",".$arr2[$i]."\n";
}
$tofile = fopen($filename, "w"); fputs($tofile, $file_txt); fclose($tofile);
?>
[Back to original message]
|