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
Post a Comment