Php check problem End of line is not valid; expected "\ n" but found "\ r \ n"

I am using Sublime text editor. I want to check the Prestashop module in validator . But this shows an error, like End of line character is invalid; expected "\n" but found "\r\n" End of line character is invalid; expected "\n" but found "\r\n" This line of code contains only <?php . I searched and replaced "\ r \ n" with "\ n" from different editors. But it doesn’t work at all. Can you tell me how to solve this problem? Any help and suggestions will be really noticeable. Thanks

+5
source share
2 answers

This is a problem with the operating system. This happens when you code cross platform. Operating systems have different ways of interpreting the end of a line. Here it can help:

Convert Line Ends

In addition, sublime has a solution for this. If you are encoding Unix, make sure you change line breaks for Unix. View->Line Endings->Unix

This solution is actually a bit deeper:

http://www.cyberciti.biz/faq/howto-unix-linux-convert-dos-newlines-cr-lf-unix-text-format/

+7
source

The most elegant solution is encoding with linux, not windows, because it's simple: linux uses \ n for the string, windows use \ r \ n

most editors that are more advanced than notepad support converting a file from windows to linux-style. just browse their respective menus.

and 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 backslashes just like backslashes, and don't interpret \ n as an escape sequence for a newline, but just like backslashes and n.

0
source

Source: https://habr.com/ru/post/1242725/


All Articles