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.
Related
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.
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.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 5 years ago.
I designed one website using Wordpress on localhost and I uploaded it to online server using filezilla, everything went success but after upload, i am facing problem, error code is give below....
Parse error: syntax error, unexpected 'function' (T_FUNCTION) in /home/u610435277/public_html/wp-content/themes/zerif-lite/inc/jetpack.php on line 1
php error
I cross checked my php code several times, it is correct. my code
Please give me sufficient information
May be you did not give a <?php at your file starting. That is why id did not expect function to begin there. Check it if this might be the problem.
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Laravel 5.3 is giving an error on production server while working fine on localhost. Other than changing php version, is there any other possible solution?
Parse error: syntax error, unexpected '.', expecting '&' or variable
(T_VARIABLE) in
/var/www/html/laravel_fresh/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php
on line 475
No, there is not. You need to have at least PHP >= 5.6.4 in order to run Laravel 5.3.
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)