note 34036 deleted from function.fgetcsv by danbrown

From: Date: Sun, 17 May 2009 18:22:40 +0000
Subject: note 34036 deleted from function.fgetcsv by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155106@lists.php.net to get a copy of this message
Note Submitter: php at joestump dot net ---- For those of you having problems with Excel's version of CSV file exports (which include the infamous ^M characters in *NIX editors, such as VIM) here is a simple script to remove them and replace them in the normal UNIX newline character (\n). <? $fp = fopen('/dev/stdin','r'); while(!feof($fp)){ $line = chop(fgets($fp,4096)); $ret = ereg_replace(chr(13) . chr(10),"\n",$line); $ret = ereg_replace(chr(13),"\n",$ret); echo $ret."\n"; } fclose($fp); ?> Usage: cat file_with_windows_newlines | php -q strip_newlines.php > outfile (this works for other stuff too, like PHP "coders" who use Notepad and upload to a UNIX environment).

« previous php.notes (#155106) next »