This a problem I already had twice while deploying an application online and that I’ve solved twice by chance still without understanding what caused the issue. This is the third time and it’s still bugging me.
-
I work locally with PHP files and Notepad++ (files are encoded in UTF-8 without BOM encoded btw). Everything works great here (config: easyPHP) without PHP errors.
-
After uploading the files to a server, some files give me basic PHP errors like *unexpected T_FUNCTION in line 1* although there is no error in my code.
-
I luckily happened to open the file with windows Notepad which gave me a hint: there are no spaces or line breaks between characters (this is why PHP gives me errors). To sum up:
File opened with Notepad++:
<?php
// Comment
function() { etc... (rest of the file)...
File opened with windows notepad:
<?php//comment function(){ ... which causes error online (but not on EasyPHP)
I’ve looked everywhere and done everything i could (adding line breaks in notepad++, converting to ANSI/UTF8, etc, but the file seems like corrupted or something). It is not a script I’ve copy pasted or anything, I create all my files by adding a new *.txt document in windows and renaming it *.php.
My questions:
- Why would Notepad++ and windows notepad show me different line breaks ? Is it encoding issues ? Windows/UNIX interpreting files differently ?
- Why would this work on my computer with easy PHP and not online ?
Thanks you in advance for any answer, if not, hint.
If you are transfering your files via FTP to production server then the problem could be some ftp clients do automatic newline conversion.. check out transfering files with different ftp client or tweak it’s settings to disable automatic ascii text new lines conversion .
UPDATE:
Yes it’s probably your files are being transferred in ascii mode rather than binary, so the solution is to set Filezilla to transferred your files in binary mode, see here the actual settings https://stackoverflow.com/a/555003/352672