I am using Sublime text editor. I want to validate a Prestashop module in the validator. But it showing the error like
End of line character is invalid; expected "\n" but found "\r\n"
This line of code only contains <?php
. I have searched and replace with
"\r\n" with "\n" from different editors. But its not working at all.
Can you tell me how to solve this issue? Any help and suggestions will be really appreciable. Thanks

- 34,243
- 16
- 77
- 119

- 12,713
- 39
- 142
- 236
2 Answers
This is an operating system issue. This happens when you're coding cross-platform. Operating systems have different ways of interpreting an end of line. Here, this may help:
Also, sublime has a solution for this as well. If you're coding for Unix, make sure you change your line-breaks for Unix. View->Line Endings->Unix
This solution is actually a bit more in-depth:
http://www.cyberciti.biz/faq/howto-unix-linux-convert-dos-newlines-cr-lf-unix-text-format/
-
Thank you so much. Is there something like this for PHP Strome? – Tarun Nagpal Jun 21 '16 at 13:12
-
2@TarunNagpal Yes, in fact PHP Storm is what I use. Go to `File->Line Seperators` and change it to `LF` for Unix. Like most things in PHP Storm, if you've got your project's root directory selected when you do this, it'll convert all your files for you. If you have one file open that you're editing, it'll simply work for the one file. You can also do this with indents via `Edit->Convert Indents`. – Nate I Jun 21 '16 at 18:46
-
Thanks, It works!! – Mihir Bhatt Aug 11 '16 at 13:24
The most elegant solution would be coding with linux instead of windows - because put simply: linux uses \n for a linebreak, windows uses \r\n
most editors that are more advanced than notepad support converting file from windows-style to linux-style. just browse through their respective menus.
and to provide a solution written in PHP:
<?php
$input = file_get_contents("old.php");
$data = str_replace("\r\n", "\n", $input);
file_put_contents("new.php");
your replacement probably didn't work because most regular editors use the backslash just as the character backslash and don't interpret \n as escape-sequence for a newline-character, but simply as a backslash and an n.

- 3,420
- 4
- 20
- 30