php - Replace linendings in csv before open it -


i have csv read fopen , fgetcsv:

ini_set('auto_detect_line_endings', true); $handle = fopen($uploaddir.$filename,"r"); while (($acell = fgetcsv($handle, 1000, ";")) !== false) {     //go through rows }  

my problem csv windows have crlf (\r\n) or lf (\n) linefeed characters. have csv mac uses crlf , cr (mostly in text columns st. html text)

the cr breaks fgetcsv not correct structure of columns , rows in header columns "defined", have windoof ones.

how can replace crs (\r) lf (\n) in csv before going through lines?

edit tried passerbys idea works. thx tips

            $file_contents = file_get_contents($uploaddir.$filename);             $file_cont_tmp = str_replace("\r","\r\n",$file_contents);             $file_cont_new = str_replace("\r\n\n","\r\n",$file_cont_tmp);             file_put_contents($uploaddir.$filename,$file_cont_new); 


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -