Skip to content

Instantly share code, notes, and snippets.

@WaximeA
Created August 29, 2018 09:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WaximeA/ab250713e928793e1896f93b5b9b032c to your computer and use it in GitHub Desktop.
Save WaximeA/ab250713e928793e1896f93b5b9b032c to your computer and use it in GitHub Desktop.
Fix csv line separator
<?php
/** @var string $path */
$path = 'import-files/';
/** @var string $file */
$file = 'test.csv';
/** @var string $realFile */
$realFile = $path.$file;
function putCSVLineSeparatorToLF($file){
if (!file_exists($file)){
return false;
}
/** @var string $content */
$content = file_get_contents($file);
/** @var string $newContent */
$newContent = str_replace("\r\n", "\n", $content);
file_put_contents($file, $newContent);
return true;
}
/** @var boolean $modifs */
$newFile = putCSVLineSeparatorToLF($realFile);
/** @var string $message */
$message = 'it\'s NOK';
if ($newFile){
/** @var string $message */
$message = 'it\'s OK';
}
echo $message;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment