Mi sembra che ^M equivalga a \r...

prova con str_replace("\r", "", $testo)