|
Posted by Stefan Rybacki on 01/07/06 22:34
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Pete wrote:
> 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";
The problem is your "\n", since $arr2[$i] already seem to contains the line end
character.
> }
> $tofile = fopen($filename, "w"); fputs($tofile, $file_txt); fclose($tofile);
>
> ?>
Regards
Stefan
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1rc2 (MingW32)
iD8DBQFDwCXsyeCLzp/JKjARAqzmAJ4o3O+zNEDH5lgEWxiaHH8Iwszr9gCgi6Oz
z9MS8BfYS0MGoAfXKkRfHQg=
=ZmTC
-----END PGP SIGNATURE-----
Navigation:
[Reply to this message]
|