PHP T_STRING Line 1 Newline Error When Uploading From Windows to Apache/Nginx
Oct 30, 2014ProgrammingComments (0)
If your PHP source files only use a carriage return (\r) and not a carriage return line feed (\r\n) or line feed (\n), then you may run into this error when uploading to an Apache or Nginx server:

Parse error: syntax error, unexpected [...] (T_STRING) in [...] on line 1
This happens because the *nix-based servers often strip carriage returns, which would leave no line breaks at all in your source code. The error will be hard to trace down as unexpected T_STRING is commonly associated with a missing semicolon.

Under normal circumstances you'll never run into this problem as Windows uses carriage return line feed (\r\n) and Linux/Mac uses line feed (\n). Only old Mac OS 9 and earlier used just the carriage return (\r), but you're probably not using one of those. Chances are you accidentally changed the type of newline character your text editor uses, or there was some other mishap.


How To Fix It


To fix the problem, check all your source files using a text editor that can show the actual newline characters, such as Notepad++ (it's under View > Show Symbol > Show End of Line). Convert any instances of just a carriage return (\r) to the correct type of newline. In Notepad++, it's under Edit > EOL Conversion.
Comments (0)
Add a Comment
No comments yet