Jun 272012
 

Today I was modifying someone else’s file when I noticed that when I uploaded it to the server it displayed horribly. All whitespace was gone, and in the place of newlines was ^M characters. Here’s a snapshot of how the file looked when I uploaded.

If I viewed it with ‘more filename.php’ I didn’t see the ^M but it looked as if the whole file was on one line, and some characters had been replaced by {. Strange.

It does not affect the server’s ability to run the file, but it does make maintenance a nightmare if you ever have to edit the file in the future.

I had been using Notepad++ (notepad plus plus) to edit it, and I had never had this problem with any of my files. Turned out the file had originally been made on a Mac, which caused these weird characters to show up (sometimes it happens on Windows too).

Luckily there’s an easy fix. With the file open in Notepad++, simply go to the Edit menu -> EOL Conversion -> Windows. It might also work if you choose Unix too. Then save the file, re-upload and you’re golden!

Hope that helps!

  14 Responses to “Getting rid of ^M newline characters in Notepad++”

  1. This helped me and I really appreciate this.. well done

  2. Thanks for posting this. I struggled with searching for a fix to very cryptic parse errors (unexpected T_STRING, unexpected $end) until I found this. Most advice online says it must be a missing curly bracket.

  3. Thanks dude

  4. helped me too… Thanks for the quick and helpful instructions

  5. Thank you!

  6. thanks lot..this really helped.

  7. Thanks a lot!!!

  8. Thanks! I knew it was there but lost it.

  9. thanks!!

  10. Thank you!! this helped me:)

  11. Thanks!!

  12. thank you 🙂

  13. Thank you. This was really helpful !!

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)