Home > Backend Development > PHP Tutorial > Parse Error: syntax error, unexpected $end error_PHP tutorial

Parse Error: syntax error, unexpected $end error_PHP tutorial

WBOY
Release: 2016-07-13 10:55:56
Original
1679 people have browsed it

Today, I encountered the error message Parse error: syntax error, unexpected $end during development. According to your own requirements, it may be that the if else does not appear in pairs. Let's summarize the problems and solutions.

Maybe it’s some features of PHP that I’m not familiar with, but as I write more, I’ll gradually get used to it...

Here is a code writing and debugging problem. The error is as follows:

Parse error: syntax error, unexpected $end in D:xampphtdocsguestBookguestBook.php on line 330

Look at line 330 of the program, the last line of code. What’s wrong with this? Searched on google and found:

In PHP 5, the following error may appear as an error entry in Apache error log or simply displays on PHP web page, even if calling to php scripts with php_info() works perfectly and successfully returns information on PHP configurations:

Parse Error: syntax error, unexpected $end in ….. scripts.php on line …

The error may caused by a missing curly bracket in PHP script coding. Besides, it may also caused by error in PHP coding in class definition, as in PHP, a class definition cannot be broke up and distributed into multiple files, or into multiple PHP blocks, unless the break is within a method declaration.

But more commonly, the error is often caused by the use of Short Open tags in PHP,

To use short open tags, it must be enabled in PHP.INI. Search for short_open_tag in PHP.INI, and change the value to On. The line should look line:

short_open_tag = On

Trying that my English is not good? After looking at several other searches, none of them got to the point, so let’s look at English. Although it can’t be translated exactly, the general meaning is clear:

The error occurred because short tags were used. You can set short_open_tag = On in php.ini

It turns out that Parse error prompts are usually syntax errors. Open tags are used and statements are not ended, which are some basic mistakes in programming, such as not paying attention to adding ";" at the end of the statement or forgetting if(){...} later. "}" ;Forgot "?>". Checking the code carefully, it turns out that "}" is missing somewhere, and the modified program runs normally

Examples


conn.php

/*
* bkJiaJob v1.0
* Programmer: Msn/QQ haowubai@hotmail.com (925939)
* www.php100.com Develop a project PHP - MySQL - Apache
* Window 2003 - Preferences - PHPeclipse - PHP - Code Templates
*/

$conn = @ mysql_connect("localhost", "root", "dong") or die("Database link error");
mysql_select_db("news", $conn);
mysql_query("set names 'GBK'"); //Use GBK Chinese encoding;

function htmtocode($content) {
$content = str_replace("n", "
", str_replace(" ", " ", $content));
return $content;
}

//$content=str_replace("'","‘",$content);
//htmlspecialchars();

?>

/*
* bkJiaJob v1.0
* Programmer: Msn/QQ haowubai@hotmail.com (925939)
* www.php100.com Develop a project PHP - MySQL - Apache
* Window 2003 - Preferences - PHPeclipse - PHP - Code Templates
*/
include("conn.php");

include("head.php");
$SQL="SELECT * FROM `message` order by id desc";
$query=mysql_query($SQL);
while($row=mysql_fetch_array($query)){
?>








Title: User:
Content: echo htmtocode($row[content]);
?>

}
?>
The following error occurs when running
Parse error: syntax error, unexpected $end in E:wampwwwleave_messagelist.php on line 35

The reason for the error is here
}
?>
Change to
}
?>

Solution

Just change the title, content, and user to This will do the trick. The function is

This is not important, at most it just cannot display the data
The reason for the error is here
}
?>
Change to
}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632209.htmlTechArticleToday when I was developing, I encountered an error message about Parse error: syntax error, unexpected $end. Please check according to your own requirements. It may be that if else does not appear in pairs, let’s summarize it below...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template