note 47594 deleted from function.fgetcsv by danbrown

From: Date: Sun, 17 May 2009 18:18:37 +0000
Subject: note 47594 deleted from function.fgetcsv by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-155098@lists.php.net to get a copy of this message
Note Submitter: Daffy ---- This is a little sniplet for all users who has problems with Excel csv files. This functions does almost the same like the linux shell program dos2unix. /* ------------------8<------------------------*/ function dos2unix ($filename) { //open original file $fp = fopen($filename,'r'); //open original file $fptmp = fopen($filename.'_tmp','w'); while(!feof($fp)){ $line = chop(fgets($fp,4096)); $ret = ereg_replace(chr(13) . chr(10),"\n",$line); $ret = ereg_replace(chr(13),"\n",$ret); fwrite($fptmp,$ret); } fclose($fp); fclose($fptmp); //remove original file unlink($filename); //move converted file to old filename copy($filename.'_tmp', $filename); //remove temp file unlink($filename.'_tmp'); } /* ------------------8<------------------------*/

« previous php.notes (#155098) next »