note 34036 added to function.fgetcsv
| From: | php at joestump dot net | Date: | Mon, 14 Jul 2003 12:58:42 +0000 |
| Subject: | note 34036 added to function.fgetcsv | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-52083@lists.php.net to get a copy of this message | ||
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).
----
Manual Page -- http://www.php.net/manual/en/function.fgetcsv.php
Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34036
Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34036&report=yes
Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34036&report=yes