Re: Re: file() and macintosh line break
| From: | Josh & Valerie McCormack | Date: | Fri, 03 May 2002 14:59:10 +0000 |
| Subject: | Re: Re: file() and macintosh line break | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-95909@lists.php.net to get a copy of this message | ||
I was having a tough time with a Mac file uploaded and squeezed into one line. My friend Shawn helped me write the following which cleans it up. Remove the echo statement to just change it and not see the change. Also, avoid trying to fix the file, make a new one, if you can.
Hope this helps.
Josh
1 <?
2 $data_file = "data.csv";
3 $newdatafile = "new_data.csv";
4
5 $file=fopen($data_file, "r");
6 $newfile = fopen($newdatafile,"w");
7
8 $filecontents = fread($file,filesize($data_file));
9 echo $filecontents;
10 echo "<br><br>";
11 $newfilecontents = preg_replace("(\r\n|\n|\r)","\n",$filecontents);
12
13 echo nl2br($newfilecontents);
14
15 fwrite($newfile,$newfilecontents);
16 fclose($file);
17 fclose($newfile);
18 ?>