0

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.

Tom
  • 947
  • 1
  • 7
  • 9
  • 1
    ensure you are saving the file w/out BOM – DarkBee Dec 03 '19 at 14:40
  • 1
    A interesting test you can do: compare the two files with an hex editor and try to figure out what could be the problem looking at the differences between the two. If there are hidden differences you will find out them immediately – Edoardo Vignati Dec 03 '19 at 14:44
  • 1
    If it sees an unexpected IF on a first line that only contains ` – 04FS Dec 03 '19 at 14:50

1 Answers1

0

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.

Tom
  • 947
  • 1
  • 7
  • 9