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?
是什么问题?
10 个解决方案
#1
241
You should avoid this (at the end of your code):
您应该避免这样(在代码的末尾):
{?>
and this:
这:
<?php}
You shouldn't put brackets directly close to the open/close php
tag, but it separate with a space:
你不应该把括号直接放在打开/关闭的php标签上,但它与空格分开:
{ ?>
<?php {
also avoid <?
and use <?php
也避免< ?和使用< ? php
#2
58
I had the same error, but I had it fixed by modifying the php.ini
file.
我有相同的错误,但是我修改了php。ini文件。
Find your php.ini file see Dude, where's my php.ini?
找到你的php。ini文件,我的php.ini在哪里?
then open it with your favorite editor.
然后用您最喜欢的编辑器打开它。
Look for a short_open_tag
property, and apply the following change:
寻找一个short_open_tag属性,并应用以下更改:
; short_open_tag = Off ; previous value
short_open_tag = On ; new value
#3
18
I had the same error, but I had it fixed by modifying the php.ini and / or editing the PHP file!
我有相同的错误,但是我修改了php。ini和/或编辑PHP文件!
There are two different methods to get around the parse error syntax.
有两种不同的方法来绕过语法错误语法。
Method 1 (Your PHP file)
Avoid in your PHP file this:
避免在PHP文件中:
<? } ?>
Make sure you put it like this
一定要像这样。
<?php ?>
Your code contains
<? ?>
代码包含< ?? >
NOTE: The missing
php
after<?
!注意:
Method 1 (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 with Ctrl + F
!), and apply the following change:
还有一个简单的方法来解决你的问题。搜索short_open_tag属性值(在文本编辑器中使用Ctrl + F!),并应用以下更改:
; short_open_tag = Off
to
来
short_open_tag = On
NOTE: Reload your Server (like for example: Apache) and reload your PHP webpage in your browser.
注意:重新加载您的服务器(例如:Apache)并在浏览器中重新加载PHP页面。
#4
9
Just go to php.ini then find short_open_tag= Off
set to short_open_tag= On
php去就行了。然后找到short_open_tag= Off设置为short_open_tag= On。
#5
5
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.
例如,如果您使用方法的控制器类,并且意外地删除了最后的括号,它关闭了整个类,您将会得到这个错误。
class someControler{
private $varr;
public $varu;
..
public function method {
..
}
..
}// if you forget to close the controller, you will get the error
#6
4
also, look for a comment // that breaks the closing curly brace
另外,寻找一个注释//它可以打破关闭的花括号。
if (1==1) { //echo "it is true"; }
if (1==1) {//echo“it is true”;}
the closing curly brace will not properly close the conditional section and php won't properly process the remainder of code.
关闭的花括号将不能正确地关闭条件部分,而php将不能正确处理剩余的代码。
#7
3
Look for any loops or statements are left unclosed.
I had ran into this trouble when I left a php foreach: tag unclosed.
当我给每个人留下一个php时,我遇到了这个麻烦:标签未关闭。
<?php foreach($many as $one): ?>
Closing it using the following solved the syntax error: unexpected end of file
使用下面的方法关闭它,解决了语法错误:文件的意外结束。
<?php endforeach; ?>
Hope it helps someone
希望它能帮助一些人
#8
2
I saw some errors, which I've fixed below.
我看到了一些错误,我已经改正了。
This is what I got as being erroneous:
这就是我的错误所在:
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";
}
This is how I would have done it:
我就是这样做的:
<html>
some code
<?php
function login()
{
if (empty ($_POST['username']))
{
return false;
}
if (empty ($_POST['password']))
{
return false;
}
$username = trim ($_POST['username']);
$password = trim ($_POST['password']);
$scrambled = md5 ($password . 'foo');
$link = mysqli_connect('localhost', 'root', 'password');
if (!$link)
{
$error = "Unable to connect to the database server";
include 'error.html.php';
exit ();
}
if (!mysqli_set_charset ($link, 'utf8'))
{
$error = "Unable to set database connection encoding";
include 'error.html.php';
exit ();
}
if (!mysqli_select_db ($link, 'foo'))
{
$error = "Unable to locate the foo database";
include 'error.html.php';
exit ();
}
$sql = "SELECT COUNT(*) FROM admin WHERE username = '$username' AND password = '$scrambled'";
$result = mysqli_query ($link, $sql);
if (!$result)
{
return false;
exit ();
}
$row = mysqli_fetch_array ($result);
if ($row[0] > 0)
{
return true;
}
else
{
return false;
}
}
if (login())
{
echo '<h2>Welcome Administrator</h2>
<a href=\"upload.php\">Upload Files</a>
<br />
<a href=\"points.php\">Edit Points Tally</a>';
}
else
{
echo "Incorrect login details. Please login";
}
?>
some more html code
</html>
#9
2
Avoid this as well <? } ?>
make sure you put <?php } ?>
避免这一点?}?>确保你放了
#10
0
Also, another case where it is hard to spot.
另外,还有一种情况很难发现。
<?php
function () {
}
The file above returns the erro Parse error: syntax error, unexpected end of file in
while the below does not.
上面的文件返回erro解析错误:语法错误,文件的意外结束,而下面没有。
<?php
function () {
};
#1
241
You should avoid this (at the end of your code):
您应该避免这样(在代码的末尾):
{?>
and this:
这:
<?php}
You shouldn't put brackets directly close to the open/close php
tag, but it separate with a space:
你不应该把括号直接放在打开/关闭的php标签上,但它与空格分开:
{ ?>
<?php {
also avoid <?
and use <?php
也避免< ?和使用< ? php
#2
58
I had the same error, but I had it fixed by modifying the php.ini
file.
我有相同的错误,但是我修改了php。ini文件。
Find your php.ini file see Dude, where's my php.ini?
找到你的php。ini文件,我的php.ini在哪里?
then open it with your favorite editor.
然后用您最喜欢的编辑器打开它。
Look for a short_open_tag
property, and apply the following change:
寻找一个short_open_tag属性,并应用以下更改:
; short_open_tag = Off ; previous value
short_open_tag = On ; new value
#3
18
I had the same error, but I had it fixed by modifying the php.ini and / or editing the PHP file!
我有相同的错误,但是我修改了php。ini和/或编辑PHP文件!
There are two different methods to get around the parse error syntax.
有两种不同的方法来绕过语法错误语法。
Method 1 (Your PHP file)
Avoid in your PHP file this:
避免在PHP文件中:
<? } ?>
Make sure you put it like this
一定要像这样。
<?php ?>
Your code contains
<? ?>
代码包含< ?? >
NOTE: The missing
php
after<?
!注意:
Method 1 (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 with Ctrl + F
!), and apply the following change:
还有一个简单的方法来解决你的问题。搜索short_open_tag属性值(在文本编辑器中使用Ctrl + F!),并应用以下更改:
; short_open_tag = Off
to
来
short_open_tag = On
NOTE: Reload your Server (like for example: Apache) and reload your PHP webpage in your browser.
注意:重新加载您的服务器(例如:Apache)并在浏览器中重新加载PHP页面。
#4
9
Just go to php.ini then find short_open_tag= Off
set to short_open_tag= On
php去就行了。然后找到short_open_tag= Off设置为short_open_tag= On。
#5
5
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.
例如,如果您使用方法的控制器类,并且意外地删除了最后的括号,它关闭了整个类,您将会得到这个错误。
class someControler{
private $varr;
public $varu;
..
public function method {
..
}
..
}// if you forget to close the controller, you will get the error
#6
4
also, look for a comment // that breaks the closing curly brace
另外,寻找一个注释//它可以打破关闭的花括号。
if (1==1) { //echo "it is true"; }
if (1==1) {//echo“it is true”;}
the closing curly brace will not properly close the conditional section and php won't properly process the remainder of code.
关闭的花括号将不能正确地关闭条件部分,而php将不能正确处理剩余的代码。
#7
3
Look for any loops or statements are left unclosed.
I had ran into this trouble when I left a php foreach: tag unclosed.
当我给每个人留下一个php时,我遇到了这个麻烦:标签未关闭。
<?php foreach($many as $one): ?>
Closing it using the following solved the syntax error: unexpected end of file
使用下面的方法关闭它,解决了语法错误:文件的意外结束。
<?php endforeach; ?>
Hope it helps someone
希望它能帮助一些人
#8
2
I saw some errors, which I've fixed below.
我看到了一些错误,我已经改正了。
This is what I got as being erroneous:
这就是我的错误所在:
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";
}
This is how I would have done it:
我就是这样做的:
<html>
some code
<?php
function login()
{
if (empty ($_POST['username']))
{
return false;
}
if (empty ($_POST['password']))
{
return false;
}
$username = trim ($_POST['username']);
$password = trim ($_POST['password']);
$scrambled = md5 ($password . 'foo');
$link = mysqli_connect('localhost', 'root', 'password');
if (!$link)
{
$error = "Unable to connect to the database server";
include 'error.html.php';
exit ();
}
if (!mysqli_set_charset ($link, 'utf8'))
{
$error = "Unable to set database connection encoding";
include 'error.html.php';
exit ();
}
if (!mysqli_select_db ($link, 'foo'))
{
$error = "Unable to locate the foo database";
include 'error.html.php';
exit ();
}
$sql = "SELECT COUNT(*) FROM admin WHERE username = '$username' AND password = '$scrambled'";
$result = mysqli_query ($link, $sql);
if (!$result)
{
return false;
exit ();
}
$row = mysqli_fetch_array ($result);
if ($row[0] > 0)
{
return true;
}
else
{
return false;
}
}
if (login())
{
echo '<h2>Welcome Administrator</h2>
<a href=\"upload.php\">Upload Files</a>
<br />
<a href=\"points.php\">Edit Points Tally</a>';
}
else
{
echo "Incorrect login details. Please login";
}
?>
some more html code
</html>
#9
2
Avoid this as well <? } ?>
make sure you put <?php } ?>
避免这一点?}?>确保你放了
#10
0
Also, another case where it is hard to spot.
另外,还有一种情况很难发现。
<?php
function () {
}
The file above returns the erro Parse error: syntax error, unexpected end of file in
while the below does not.
上面的文件返回erro解析错误:语法错误,文件的意外结束,而下面没有。
<?php
function () {
};