0

I downloaded php files through ftp. After editing them and uploading them again, I basically always get an error on line 1 with one of my first actions:

Parse error: syntax error, unexpected '{' in "...etc.

The weird thing is, they work correctly on my local host. They also display fine when I open them in my IDE (jetBrains phpStorm). However, if I open my files (from local host) in for example Notepad, the complete file is on one line.

Edit: Since my question was marked as a duplicate, i think i need to emphasise this: There is nothing wrong with the code itself. It works perfectly on my local host. I know what unexpected '{' means. The error i entered above is just an example. If the first line was an include(), i would get unexpected include etc. If i copy paste the exact code into a new file, the error is gone.

I did find out how to fix it for one file. If I simply copy the code in phpStorm, create a new file and paste it in there, it works. However, there are around 500 files, so doing this manually would take a lot of time. So my questions are:

  1. What causes this kind of behaviour and how can i prevent this in the future.
  2. How can i fix this for my current project.
user4493177
  • 750
  • 11
  • 32
  • I have a question to the people who marked this as a duplicate: Did you even read the post? Ofcourse i know what the syntax error means. But i get an error like that in every file, even though there is NOTHING wrong with the code on my local host. The error was just an example. – user4493177 May 09 '15 at 11:05

1 Answers1

1

Check the type of end-of-line / newline character being inserted by your IDE.

I had a similar problem with Notepad++, and the setting to change was: Edit >> EOL Conversion >> (and in my case I has to set it to Windows Format)

foxbeefly
  • 510
  • 3
  • 13
  • I Changed them to windows (\r\n\) according to this: https://www.jetbrains.com/phpstorm/help/configuring-line-separators.html However i still have a problem. I also noticed there are a lot of spaces added, sometimes even between variables. So $var will display in notepad as $ var – user4493177 May 08 '15 at 06:25