PHP Parse error: syntax error, unexpected end of file
×


PHP Parse error: syntax error, unexpected end of file

1536

When we write a program in html and put some PHP into it and working on a loop or if_else , we have to make sure that the opening or closing brackets are in the right place of the code, if they are not it displays an error:

|PHP Parse error: syntax error, unexpected end of file.

For Example:

<html>
<?php
if(condition){?>
<div></div>
<?php } ?>
</html>

Output:

|PHP Parse error: syntax error, unexpected end of file.

For resolving this error we have to make sure that the opening or closing brackets are in the right places of the code.


For example:

<html>
<?php
if(condition){
?>
<div></div>
<?php

?>
</html>

Another reason of this error is a missing curly bracket in PHP script coding:

<?php
while(condition){
do something...
?>

In the above example the opening curly bracket of the while loop is available but closing is not then, the output also caused the same error:

|PHP Parse error: syntax error, unexpected end of file, at line 4.

To avoid this error we have to open and close the curly brackets properly.

The third reason for this error is class definition in PHP program, because a class definition cannot be divided into multiple parts of files or multiple PHP blocks, unless the break is within a method declaration.

This error is also arrives when developer want to use short opening tags "<?" instead of full tag "<?php" in PHP programs.

To avoid these errors we should prefer full opening tags in PHP scripting code rather than short opening tags, for better results.

Note

the above solution works with all the earlier versions of PHP

By Using these solution and information we can resolve the error.



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments