php files newlines missing [duplicate] - php

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 7 years ago.
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:
What causes this kind of behaviour and how can i prevent this in the future.
How can i fix this for my current project.

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)

Related

PHP - Website issue after local save and upload [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
I am very new to PHP and am trying to modify an existing PHP file. Even when I only add an additional line and save the code, I receive an error on the website after uploading:
Parse error: syntax error, unexpected 'if' (T_IF) in /home/.../file.php on line 1
On line 1, the code starts with
<?php
When I only leave <? at the beginning, I get this error:
Parse error: syntax error, unexpected (T_VARIABLE) on line 1
At the end, there should not be any error, as I am not changing any single line of code.
When uploading the original file back on the server, the error disappears.
I am using XAMPP and PHPstorm with 7.3 interpreter.
In my case, it seemed to be something with the BOM encoding, as commented by DarkBee - Thanks!
I opened the file in Notepadd++, made my modification and set
Encoding -> Convert to UTF-8
before saving and it works.

New PHP site on a new server - Parse error: syntax error, unexpected '?> ' [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Reference - What does this error mean in PHP?
(38 answers)
Closed 4 years ago.
I tried to set up a site from my old to new server, checked over the databases and set it up exactly like it should but it keeps throwing errors such as:
Parse error: syntax error, unexpected '?> ', expecting function (T_FUNCTION) in /search/index.php on line 2536
I can fix this by adding a } at the end of the page, but that wasn't needed for when it was on the other server and even after that there were more problems that followed up after:
Notice: Use of undefined constant SUBPAGE_LEVEL_1 - assumed 'SUBPAGE_LEVEL_1' in
would appear all over the site, I know the issue related to that is due to the constant not actually being defined on that particular page.
The main thing is I believe this is related to my php ini settings on the new server, these errors never appeared on the old server.
For reference my new server (the one with the errors) are on:
PHP 5.6.36-1+ubuntu18.04.1+deb.sury.org+1 (cli)
and the old server:
PHP 5.6.37 (cli)
I've looked up the differences between .36 to .37 but I've never noticed anything that stood out to me, is it because of this or am I overlooking something really obvious?
Update: error reporting is in a file called the config.php, it's not being loaded into the sitewide (as it did with the old server, I do know however it's being included because its the file that's required to make the site work)
Once I manually add the error report code into the header.php it fixes some but not all the issues and I feel I shouldn't have to touch any of the site code as it is.

Wordpress Parse error: syntax error [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
Apologies for the undetailed description on my last question. I installed wordpress with Jevelin Theme on linux server, its a really basic setup, i had'nt edited any code whatsoever with the setup, or added any unecessary plugins, it was working straight out the box untill i have recently got this error:
Parse error: syntax error, unexpected '<' in
/tmp/theme_temp_setupgwHCl7 on line 2.
I have tried to do the following apon reading some other comments with the same problem:
Delete current theme (no effect)
Rename plugins folder (no effect)
I connot even access wp-admin upon deleting the theme. Get the same error. I cannot locate tmp/theme_temp on my server either. I see no such directory. Any help would be greatly appreciated. ------
I'll guess you've embedded html inside a block in the offending file (somewhere near the top).
You really need to provide a much more detailed problem description to get any real help.

Sudden PHP parse error on RHEL

I have various PHP files, none of which have been modified prior to the app working and it breaking. My problem is that for some reason, these files are suddenly throwing PHP parse errors for things like 'unexpected' square brackets in seemingly random places throughout the file, but upon manually checking the file, the syntax is correct.
The only thing I did that could have 'altered' the files would be various chmod operations to change the permissions. But how/why would this change the actual content of the files?
The files are called on boot just as they always have been, and have worked fine in the past, up until the recent chmod changes.
Is this permanent, or will I just have to restore my system from an earlier time?
RHEL 6.5, PHP 5.4.
Edit:
Example of the error:
PHP Parse error: syntax error, unexpected '[' in /var/ptc/CRM-dev/tools/init on line 122
What's on line 122:
$files = [];
Another example:
PHP Parse error: syntax error, unexpected '[', expecting ')' in /var/ptc/CRM-dev/vendor/react/promise/src/functions.php on line 68
What's on line 68:
return resolve([]);
But these files themselves haven't been changed (as far as I'm aware), and the syntax looks correct.
phpinfo() gives 5.4.39, which is the same as when running php -v on the server.
If the PHP version has been changed then it may be stumbling on the PHP 5.4 square bracket array syntax.
Use phpinfo(); to be sure that the PHP version running the web server is the same as the one you're using on the CLI.

Tabs, line breaks encoding when uploading PHP files on my server

I am writing a PHP application and developing it localy (easyPHP). However, when I transfer my files on my server (FTP), i get on of the following error :
Parse error: syntax error, unexpected $end in /homez.93/dockydoc/_apps/dockydocs/include/functions.php on line xx
Error unexpected error function on line 1
Etc..;
When I re-download my PHP files and open them with Notepad++ or the classic windows pad, their are no more spaces, line break or tabulation in my file ! This result in the server not to be able to read PHP.
My files are UTF8 without BOM encoded (in Notepad++). I can't find the solution to this proble despite thorought search on the Internet... I anyone could help .. :)
Thanks,
Romain
Make sure you are using ASCII mode data connection when uploading the files over FTP. If you are set to binary, I believe this causes this!

Categories