PHP Removing Windows ^ M Character

I have a CSV that I download from a source that I do not control, and the end of each line is

^M 

when printing to bash terminal. How can I programmatically handle this input in PHP?

+5
source share
3 answers

What you see is a Windows control character. To get rid of this in PHP, you need to make    $file = str_ireplace("\x0D", "", $file) it work, be it hexadecimal lowercase or uppercase.

+15
source

^M is a carriage return, you can delete it with:

$string = str_replace( "\r", "", $string);
+3
source

PHP , CSV , .

ini_set('auto_detect_line_endings', true);
+1

All Articles