info
2022-07-13
Incompatible line breaks when working with windows or mac files?
No problem!
Win&Mac -> Unix fast and clean:
$meinfile = "meinfile.csv"; $meinfile_inhalt = file_get_contents($meinfile); $meinfile_inhalt = preg_replace('/\r\n?/', "\n", $meinfile_inhalt); $corrmeinfile = "meinfile_neu.csv"; $fp = fopen ($corrmeinfile,"w"); fwrite($fp,$meinfile_inhalt); fclose($fp); echo "line ends replaced";
Unix ->Win
$infile = "infile.csv"; $outfile = "infile_windows.csv"; $contents = file_get_contents($infile); $contents = str_replace("\n", "\r\n", $contents); file_put_contents($outfile, $contents); echo "Line endings converted from Unix to Windows format.\n";
Enjoy :)
You are also free to use my online converter: