Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php validation issue End of line character is invalid; expected "\n" but found "\r\n" [duplicate]

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

like image 238
NewUser Avatar asked Feb 10 '16 18:02

NewUser


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:

Convert line endings

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/

like image 195
Nate I Avatar answered Nov 11 '22 12:11

Nate I


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.

like image 44
Franz Gleichmann Avatar answered Nov 11 '22 14:11

Franz Gleichmann