Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by mlewis54 for Change line feed of csv file to the same one

You have a number of options right in php. For example:

$f=file_get_contents("files/uploads/$fileName");
$f=str_replace("\r","",$f);
file_put_contents("files/uploads/$filename",$f);

This will strip all RETURN characters ("\r") from the input and write the file back with just linefeeds ("\n").

I have yet to see a CSV/Spreadsheet file with just "\r" characters, but supposing that is the case you could also do: str_replace("\r","\n") and then reduce "\n\n" to a single "\n" (again using str_replace).

There is also a REGEX-based solution, but the regex-part of my brain is a little fried this morning.


Viewing latest article 1
Browse Latest Browse All 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>