I got an error:
Parse error: syntax error, unexpected end of file in the line
With this code:
<html>
<?php
function login()
{
// Login function code
}
if (login())
{?>
<h2>Welcome Administrator</h2>
<a href=\"upload.php\">Upload Files</a>
<br />
<a href=\"points.php\">Edit Points Tally</a>
<?php}
else
{
echo "Incorrect login details. Please login";
}
?>
Some more HTML code
</html>
What's the problem?
Just go to php.ini then find
short_open_tag= Off
set toshort_open_tag= On
Check that you closed your class.
For example, if you have controller class with methods, and by accident you delete the final bracket, which close whole class, you will get this error.
You should avoid this (at the end of your code):
and this:
You shouldn't put brackets directly close to the open/close
php
tag, but it separate with a space:also avoid
<?
and use<?php
Avoid this as well
<? } ?>
make sure you put<?php } ?>
There are two different methods to get around the parse error syntax.
Method 1 (Your PHP file)
Avoid in your PHP file this:
Make sure you put it like this
Method 2 (php.ini file)
There is also a simple way to solve your problem. Search for the
short_open_tag
property value (Use in your text editor withCtrl + F
!), and apply the following change:to
According to the description of core php.ini directives,
short_open_tag
allows you to use the short open tag (<?
) although this might cause issues when used with xml (<?xml
will not work when this is enabled)!Look for any loops or statements are left unclosed.
I had ran into this trouble when I left a php foreach: tag unclosed.
Closing it using the following solved the syntax error:
unexpected end of file
Hope it helps someone