PHP Removing Windows ^M Character

Viewed 10412

I have a CSV I am downloading from a source I'm not in control of and the end of each line is a

^M 

character when printed to a bash terminal. How can I sanitize this input programmatically in PHP?

3 Answers

You can also ask PHP to auto detect any weird line endings by just adding in this line before reading the CSV file and you won't be required to do anything else.

ini_set('auto_detect_line_endings', true);
Related