How to identify in the CSV file whether the line ends with "\n","\r" or "\n\r"


How to identify in the CSV file whether the line ends with "\n","\r" or "\n\r"

Since in mac it takes as CR as the new line.
In Windows CRLf as the new line.
In Linux Lf. as the new line.

I have a csv file which is created in mac,linux or windows it is unknown,i need to import the file.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Cornelia YoderArtistCommented:
Have you tried using PHP_EOL?
Paul SDesktop Support Manager / Network AdministratorCommented:
here is a good sample form for splitting something using a list of delimiters. just substitute \n, \r, \n\r

Here is my approach to have exploded output with multiple delimiter.


//$delimiters has to be array
//$string has to be array

function multiexplode ($delimiters,$string) {
    $ready = str_replace($delimiters, $delimiters[0], $string);
    $launch = explode($delimiters[0], $ready);
    return  $launch;

$text = "here is a sample: this text, and this will be exploded. this also | this one too :)";
$exploded = multiexplode(array(",",".","|",":"),$text);


//And output will be like this:
// Array
// (
//    [0] => here is a sample
//    [1] =>  this text
//    [2] =>  and this will be exploded
//    [3] =>  this also
//    [4] =>  this one too
//    [5] => )
// )

Ray PaseurCommented:
You can use file().  All of the PHP functions are documented on the web site.  You might use FILE_IGNORE_NEW_LINES as a flag.  But a better approach would be to post your test data set here with the question.  You can post the information in the code snippet or post a link to your test files.  Then we can write the programming that will handle the end of line characters and show you exactly how it's done.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.